Skip to main content

Posts

Showing posts from October, 2012

Sample C Program To Delete All Vowels From A Sentence / String.

void main()   {      char sent[ ] = "She sells seashells on the seashore";      int i;      for(i = 0; sent[i] != 0; i++)        {             if(sent[i] == 97 || sent[i] == 101 || sent[i] == 105 || sent[i] == 111 || sent[i] == 117)                {                    for(;sent[i + 1] != 0; i++)                        sent[i]=sent[i + 1];                                      sent[i] = '\0';                    i =- 1;                }        }      printf("\n %s", sent);   } ALSO CHECK THESE C PROGRAMS: 86.  C Program To Accept A String & Display It. 87.  C Program To Find The Length Of A String. 88.  C Program To Concatenate Two Strings. 89.  C Program To Compare Two Strings. 90.  C Program To Swap Two Strings. 91.  C Program To Swap Two Strings Using strcpy() Function. 92.  C Program To Sort A Given Number Of Strings Using strcmp() Function. 93.  C Program To Check Whether A String Is Palindrome Or Not. 94.  C Program

Sample C Program To Count The Number Of Occurrences Of Any Two Vowels In Succession In A Line Of Text.

This program lets the user know the number of occurences of any two vowels in succession in the text passed in the program. For example, in the sentence “Please read the document carefully and then sign the gratuity form.” Such occurrences are ea, ea, ui. void main()   {      char sent[ ] = "Please read the document carefully and then sign the gratuity form.";      int i, c;      for(i = 0, c = 0; sent[ i ] != '\0'; i++)         {             if( (sent[i] == 97 || sent[i] == 101 || sent[i] == 105 || sent[i] == 117 )&&(sent[i + 1] == 97 || sent[i + 1] == 101 || sent[i + 1] == 105 || sent[i + 1] == 111 || sent[i + 1] == 117))             c++;         }      printf("\nThere are %d occurences of two vowels in succession",c);   } ALSO CHECK THESE C PROGRAMS: - C Program to count the number of words, characters, alphabets, vowels, consonants and digit in a line of text.  - C Program to accept two string and compare the strings are eq

Sample C Program To Compare Two Dates Using Structures.

In this program user enters two dates for comparison. In order to store date we will use structure say date that contains three members namely date, month and year. If the dates are equal then display message as “Dates are Same." otherwise “Both the dates are different”.  void main() {     int i, f = 0;     struct date       {          int date;          int month;          int year;       };     struct date d[2];     for(i = 0; i < 2; i++)       {          printf("\n Enter day for the %d date \n", i + 1);          scanf("%d",&d[i].date);          printf("\n Enter the month for the %d) date \n", i + 1);          scanf("%d",&d[i].month);          printf("\n Enter the year for the %d) date \n", i + 1);          scanf("%d",&d[i].year);       }     if(d[0].date == d[1].date)       {          if(d[0].month == d[1].month)             {                 if(d[0].year == d[1].year)    

Sample C Program to accept a string and print the reverse of the given string.

40) Sample C Program to accept a string and print the reverse of the given string. # include <stdio.h> # include <conio.h> main( ) { int i, j; char name[80]; clrscr( ); printf("Enter a string"); gets(name); for(i = 0; i < 80 && ((name [i] = getchar()) != '\n'); i++);      if(name[i]= ='\n')          name[i]='\0'; for(j=i;j>=0;j--)       putchar(name[j]); printf("Is the reverse of given string"); getch( ); } 41) Sample C Program to accept a string and check whether the given string is palindrome or not. # include <stdio.h> # include <conio.h> main( ) { int i, lim, c, check = 1; char word[80]; clrscr( ); printf("Enter a string"); for(i = 0; i < 80 && ((word [i] = getchar()) != '\n'); i++); lim = i - 1; c = lim / 2; for(i = 0; i <= 0; i++, lim--)      if(word[i] != word[lim])        {           check = 0;           break;      

Sample C Program to accept two string and compare the strings are equal or not.

46) Sample C Program to count the number of words, characters, alphabets, vowels, consonants and digit in a line of text. # include <stdio.h> # include <conio.h> main( ) { int noa = 0, nob = 0, noc = 0, nov =0 , now = 0, noch = 0, l, I; char ch, s[100]; clrscr( ); printf(" Enter 2 lines of text: "); gets(s); l = strlen(s); for(i = 0; i < 1; i++)    {       switch(s[i])         {            case 'a':            case 'e':            case 'i':            case 'o':            case 'u':            case 'A':            case 'E':            case 'I':            case 'O':            case 'U':                          nov++;                          break;         }       if(isalpha(s[i]))            noa++;       if(isdigit(s[i]))            nod++;       if(noa[i] == ' ') && (noa[i + 1] != ' ')            now++;    } noch

Sample C Program to print upper triangle.

43) Sample C Program to print upper triangle. # include <stdio.h> # include <conio.h> main( ) { int a[4][4], i, j, c; clrscr( ); printf(" Enter the no. for which you want upper triangle: "); scanf("%d", &c); for(i = 0; i < 4; i++)    for(j = 0; j < 4; j++)        if(i < j)            a[i][j] = c;        else            a[i][j] = 0; for(i = 0; i < 4; i++)    for(j = 0; j < 4; j++)      {         printf("%d:", a[i][j]);         printf('\n');      } getch( ); } 44) Sample C Program to accept two 3 dimensional array and store addition of those into the third 3-D array . # include <stdio.h> # include <conio.h> main( ) { int a[3][3], b[3][3], c[3][3], i, j; clrscr( ); for(i = 0; i < 3; i++)    for(j = 0; j < 3; j++)      {         printf(" Enter the two values for a[%d][%d] & b[%d][%d] ", i, j, i, j);         scanf("%d %d", &a[i][

Sample C Program For Armstrong Numbers

7) Sample C Program to print sum of individual digits of given number. # include <stdio.h> # include <conio.h> main( ) { int a, b, c, d; clrscr( ); printf ( "Enter any two digit number :"); scanf ("%d", &a); b = a / 10; c = a % 10; d = b + c; printf ("Sum of individual digits of given numbers is %d", d); getch( ); } 8) Sample C Program Program to accept a three digit number and print the sum of individual digits. # include <stdio.h> # include <conio.h> main( ) { int a, b, c, n, sum; clrscr( ); printf ("Enter a Three Digit Number:"); scanf ("%d",&n); a = n / 100; b = ( ( n % 100 ) / 10 ); c = n % 10; sum = a + b + c; printf ("Sum of Individual Digits of Given Numbers is %d", Sum); getch( ); } 9. Sample C Program to accept a number and check the given number is Armstrong or not. # include <stdio.h> # include <conio.h> main( ) { int n,

Sample C Program To Print A Message.

1) Sample C Program To Print A Message. # include <stdio.h> # include <conio.h> main() { clrscr(); printf("HELLO WELCOME TO WWW.INTERVIEW-MADE-EASY.COM"); printf("Answers To All Important Interview Questions"); getch(); } 2) Sample C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. # include <stdio.h> # include <conio.h> main() { int a,b, sum; clrscr (); printf ("ENTER VALUE FOR A;"); scanf ("%d",&a); printf("ENTER VALUE FOR B;"); scanf("%d",&b); sum = a + b; printf("Sum Of Given Two Numbers are %d", sum); getch(); } 3) Sample C Program To Accept Student Roll No, Marks in 3 Subjects and Calculate Total, Average and Print it. # include <stdio.h> # include <conio.h> main() { int r, b, c, d, tot, avg; clrscr(); printf ("ENTER STUDENT RNO;"); scanf ("%d",&r); printf("ENTER FIRST SU

Sample C Program To Check Leap Year Using Logical Operator & Functions

C Program To Read Three Numbers And Print The Biggest Of Given Three Numbers. # include <stdio.h> # include <conio.h> main( ) {     int a, b, c, big = 0;     clrscr( );     printf("Enter Value For A:");     scanf("%d",& a);     printf("Enter Value For B:");     scanf("%d",& b);     print("Enter Value For C:");     scanf("%d",& c);     if (a > big)         big = a ;     if(b > big)         big = b;     if (c > big)         big = c;     printf (“Biggest Of Above Given Three Number Is %d”, big)     getch( ); } C Program To Find Whether The Given Number Is Even Or Odd Using Modulus Operator. # include <stdio.h> # include <conio.h> main() {     int n, r;     clrscr();     printf("Enter a No. ;");     scanf("%d", & n);     r = n % 2;     if(r == 0)         printf("The above given number is an even number."

Sample C Program to accept a string in upper case and print it in lower case.

28) Sample C Program to accept a string and print it by using the while loop. # include <stdio.h> # include <conio.h> main( ) { char ch; clrscr(); printf("Enter a string:"); while(( ch = getchar() ) != '\n')    putchar(ch); getch(); } 29) Sample C Program to accept a string in upper case and print it in lower case. # include <stdio.h> # include <conio.h> main( ) { char ch,c; clrscr(); printf("Enter a string in upper case:"); while(( ch = getchar( ) ) != '\n')   {      c = ch + 32;      putchar(c);   } printf(" :String In Lower Case"); getch( ); } 30) Sample C Program to accept a string in any case and print it by another case. # include <stdio.h> # include <conio.h> main( ) { char ch; clrscr( ); printf("Enter a string:");  while(( ch = getchar( )) != '\n') { if(ch >= 'A' && ch <= 'Z') putchar(ch + 32); else

Sample C Program to print numerical pyramid.

16) Sample C Program to print numeric pyramid. # include <stdio.h> # include <conio.h> main() { int i, j; clrscr( ); for(i = 1; i <= 5; i++)  {    for(j = 1; j <= i; j++)      printf("%d", j);   printf("\n");  } getch(); } 17) Sample C Program to print numerical pyramid. # include <stdio.h> # include <conio.h> main() { int i, j, l, k = 40; clrscr( ); for(i = 1; i <= 9; i += 2)  {    for(l = 1; l <= k; l++)       printf(" " );      for(j = 1; j <= i ; j++);       printf("%d", j);      printf("\n");    k = k - 2;  } getch( ); } 18) Sample C Program to print numerical diamond. # include <stdio.h> # include <conio.h> main( ) { int i, j, l, n, s, k = 40; clrscr( ); for(i = 1; i <= 9; i += 2)  {     for(l = 1; l <= k; l++)       printf(" ");     for(j = 1; j <= i; j++)        printf("\n");     k = k

C Program To Print Pyramid Of Numbers.

19) Sample C Program to print character pyramid. # include <stdio.h> # include <conio.h> main( ) { char i, j; clrscr(); for(i = 65; i <= 70; i++)  {    for(j = 65; j <= i; j++)       printf("%c", j);    printf("\n");  } getch( ); } 20) Sample C Program to print character diamond. # include <stdio.h> # include <conio.h> main( ) { char i, j, n, r; int s, sp = 40; clrscr( ); for(i = 65; i <= 75; i += 2)  {    for(s = 1; s <= sp; s++)       printf(" ");    for(j = 65; j < i; j++)       printf("%c", j);    printf("\n");    sp = sp - 2;  } sp = sp + 4; for(n = 73; n >= 65; n -= 2)  {    for(s = 1; s <= sp; s++)       printf(" ");    for(r = 65; r <= n; r++)       printf("%c",r);    sp = sp + 2;  } getch( ); } 21) Sample C Program to find biggest of two no by using ternary operator. # include <stdio.h> # include

C Program To Find Largest/Smallest Of Four Nos. Using Ternary Operator.

22) Sample C Program to find largest of four nos. by using Ternary Operator. # include <stdio.h> # include <conio.h> main( ) { int a, b, c, d, big; clrscr( ); printf("Enter the value of a:"); scanf("%d",&a); printf("Enter the value of b:"); scanf("%d",&b); printf("Enter the value of c:"); scanf("%d",&c); printf("Enter the value of d:”); scanf("%d",&d); big = (a > b)?(a > c)?(a > d)?a:d:(c > d)?c:d:(b > c)?(b > d)?b:d:(c > d)?c:d; printf("Biggest of the given 4 numbers is %d", big); getch(); } 23) Sample C Program to find smallest of four nos. by using Ternary Operator. # include <stdio.h> # include <conio.h> main( ) { int a, b, c, d, small; clrscr( ); printf("Enter the value of a:"); scanf("%d",&a); printf("Enter the value of b:"); scanf("%d",&b); printf("

C Program To Print Multiplication Table Using For Loop.

13) Sample C Program to accept a number and print mathematical table of the given no. # include <stdio.h> # include <conio.h> main( ) { int i, t; clrscr( ); printf("Which table you want:"); scanf("%d",&t); for (i = 1; i <= 10; i++)    printf("\n%d * %d = %d", t, i, i * t); getch( ); } 14) Sample C Program to print 1 to 10 mathematical tables. # include <stdio.h> # include <conio.h> main( ) { int i, j; clrscr( ); for (i = 1; i <= 10; i++)   for (j = 1; j <= 10; j++)     printf("\n%d * %d = %d", i, j, i * j); getch( ); } 15) Sample C Program to print Fibonacci series. # include <stdio.h> # include <conio.h> main( ) { int a = 0, b = 1, c = 0, i; clrscr( ); printf("%d",a); printf("\n%d",b); for (i = 1; i <= 10; i++)  {    c = a + b;    printf("\n%d", c);    a = b;    b = c;  } getch( ); }

C Program To Print ODD Numbers From 1 To 100.

10) Sample C Program to print ODD numbers from 1 to 100. # include <stdio.h> # include <conio.h> main( ) { int i; clrscr( ); for (i = 1; i <= 100; i += 2) printf("%d\n",i); getch( ); } 11) Sample C Program to print natural numbers from 1 to 100 in reverse order. # include <stdio.h> # include <conio.h> main( ) { int i; clrscr( ); for (i = 100; i >= 1; i --) printf(“%d\n”,i); getch( ); } 12) Sample C Program to print sum of the natural numbers from 1 to 100. # include <stdio.h> # include <conio.h> main( ) { int n, sum = 0, i; clrscr( ); for (i = 1; i <= 100; i ++) sum = sum + i; printf("Sum of natural numbers from 1 to 100 is %d\n",sum); getch( ); }

C Program to Check Given No. Is Armstrong Number Or Not.

37) Sample C Program to accept a number and check whether the given number is an Armstrong number or not. # include <stdio.h> # include <conio.h> main( ) { int n, arm; clrscr(); printf("Enter any 3 digit number:") scanf("%d",&n); arm = armstrong (n); if(arm == n)    printf("%d is an  Armstrong number. ",n); else    printf("%d is not an Armstrong number .",n); getch( ); } int armstrong (int n) { int a, b, c, d; a = n / 100; b = ( (n / 10) % 10); c = n % 10; d = a*a*a + b*b*b + c*c*c; return d; } 38) Sample C Program to accept a number and print the sum of given and reverse number. # include <stdio.h> # include <conio.h> main( ) { int a, b, n; clrscr( ); printf("Enter a number:") scanf("%d",&n); a = rev(n); printf("Reverse of a given number is: %d", a); b = add(n, a); printf("\n Sum of a given and reverse number is: %d", b)

C Program To Convert Uppercase To Lowercase.

25) Sample C Program to accept a character in Uppercase & print in Lowercase. # include <stdio.h> # include <conio.h> main( ) { char ch, c1; clrscr( ); printf("Enter a character in Uppercase:"); ch = getchar(); c1 = ch + 32; printf("The given character in Lowercase is:"); putchar(c1); getch(); } 26) Sample C Program to accept a character in any case and print it in another case. # include <stdio.h> # include <conio.h> main( ) { char ch, c1; clrscr( ); printf("Enter a character in any case(Uppercase/Lowercase):"); ch = getchar(); if(ch >= 65 && ch <= 90)    c1 = ch + 32; elseif(ch >= 97 && ch <= 122)    c1 = ch - 32; endif; printf("The given char in other case is:"); putchar(c1); getch(); } 27) Sample C Program to print natural number from 1 to 10 by using while loop. # include <stdio.h> # include <conio.h> main( ) { int a = 0

C Program To Find Prime Number Between 1 And 100.

34) Sample C Program to print prime numbers between 1 to 100. # include <stdio.h> # include <conio.h> main( ) { int n, i, check; clrscr(); for(i = 1; i <= 100; i++) { check = 1; for(n = 2; n <= i / 2; n++) if(i % n == 0) { check = 0; break; } if(check == 1) printf("\n %d is a prime", i); else printf("\n %d is not a prime", i); } getch( ); } 35) Sample C Program to accept two numbers and print sum of two numbers by using functions. # include <stdio.h> # include <conio.h> main( ) { int a, b, c; clrscr(); printf("Enter the value for a:") scanf("%d",&a); printf("Enter the value for b:") scanf("%d",&b); c = add(a, b); printf("Sum of two numbers is %d",c); getch( ); } int add(int x, int y) { int z; z = x + y; return z; } 36) Sample C Program to accept a number and find factorial of given number. # include <stdio.h> # incl

String Programs In C Programming Asked In Interviews.

31) Sample C Program to accept a string and print each word in new line. # include <stdio.h> # include <conio.h> main( ) { char ch; clrscr( ); printf("Enter a string :"); while( ( ch = getchar( ) ) != '\n') { putchar(ch); if(ch == ' ') printf("\n"); } getch( ); } 32) Sample C Program to accept a string and count no of capital letters, no. of small letters and no. of special characters. # include <stdio.h> # include <conio.h> main( ) { char ch; int c = 0,s = 0,s1 = 0; clrscr( ); printf("Enter a string :"); while( ( ch = getchar( ) ) != '\n')   {      if(ch >= 'A' && ch >= 'Z')         c = c + 1;      else if(ch >= 'a' && ch >= 'z')         s = s + 1;      else         s1 = s1 + 1;   } printf("No. of capital letters are %d", c); printf("No. of small letters are %d", s); printf("No.