Skip to main content

Posts

Showing posts from December, 2011

Sample C Program To Find Out The No. Of Times A Character Is Present In The String.

This is a Sample C Program To Accept A String & Find Out Whether This Character Is Present In The String. If Present Then Display How Many Times This Character Occurs. #include<stdio.h> #include<conio.h> #include<string.h> void s(char *p,char hc); void main() { char str[10]; char ch; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); printf(" \n \n Enter the character: \t "); scanf("%c",&ch); s(str,ch); } void s(char *p,char hc) { int a = 0; int i,l; l = strlen(p); for(i = 0; i < l; i++)   {      if ( p[i] == hc)        {          a++;        }      else          continue;   } printf(" \n \n The Entered Character occurs %d times. ", a); getch(); } OUTPUT:  Enter the string: Googleplus Enter the character: l The Entered Character occurs 2 times. ALSO READ: Sample C Program To Accept A String & Find Out Whether This Character Is Present I

Sample C Program To Accept A String & Find Out Whether This Character Is Present In The String.

#include<stdio.h> #include<conio.h> #include<string.h> void s(char *p,char hc); void main() { char str[10]; char ch; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); printf(" \n \n Enter the character: \t "); scanf("%c",&ch); s(str, ch); } void s(char *p,char hc) { int a; int i,l; l = strlen(p); for(i = 0; i < l; i++) { if(p[i] == hc)   {      a++;   } else      continue; } if(a >= 1)   {      printf(" \n \n Yes, the entered character is present in the string. ");   } else   {      printf(" \n \n No, the entered character is not present in the string. ");   } getch(); } OUTPUT: Enter the string: Malayalam Enter the character: z No, the entered character is not present in the string. ALSO READ: Sample C Program To Accept A String & Display It's Substring. Sample C Program To Accept A String & Display It's Alterna

Sample C Program To Accept A String & Display Number Of Each Vowels.

#include<stdio.h> #include<conio.h> #include<string.h> char vowels(char *p); void main() { char str[10]; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); vowels(str); getch(); } char vowels(char *p) { int i, l, v1 = 0, v2 = 0, v3 = 0, v4 = 0, v5 = 0, v6 = 0, v7 = 0, v8 = 0, v9 = 0, v10 = 0; l = strlen(p); printf(" \n \n The number of vowels in the string is: \t "); for( i = 0; i < l; i++ ) { if ( p[i] == 'a' )   {      v1++;   } if ( p[i] == 'e' )   {      v2++;   } if ( p[i] == 'i' )   {      v3++;   } if ( p[i] == 'o' )   {      v4++;   } if ( p[i] == 'u' )   {      v5++;   } if ( p[i] == 'A' )   {      v6++;   } if ( p[i] == 'E' )   {      v7++;   } if ( p[i] == 'I' )   {      v8++;   } if ( p[i] == 'O' )   {      v9++;   } if ( p[i] == 'U' )   {      v10++;   } else

Sample C Program To Accept A String & Display Number Of Vowels.

#include<stdio.h> #include<conio.h> #include<string.h> char vowels(char *p); void main() { char str[10]; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); vowels(str); getch(); } char vowels(char *p) { int i,l,v=0; l = strlen(p); printf(" \n \n The number of vowels in the string is: \t "); for(i = 0 ;i < l ; i++)   {      if ( p[i] == 'a' || p[i] == 'e' || p[i] == 'i' || p[i] == 'o' || p[i] == 'u' ||           p[i] == 'A' || p[i] == 'E' || p[i] == 'I' || p[i] == 'O' || p[i] == 'U' )        {           v++;        }      else           continue;   } printf("%d",v); return 1; } OUTPUT:  Enter the string: Dinosaur The number of vowels in the string is: 4 ALSO READ: Sample C Program To Accept A String & Display Vowels. Sample C Program To Accept A String & Display In Reverse. Sam

Sample C Program To Accept A String & Display Vowels.

#include<stdio.h> #include<conio.h> #include<string.h> char vowels(char *p); void main() { char str[20]; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); vowels(str); getch(); } char vowels(char *p) { int i,l; l = strlen(p); printf(" \n \n The vowels in the string are: \t "); for( i = 0; i < l; i++ )  {   if(p[i] == 'a' || p[i] == 'e' || p[i] == 'i' || p[i] == 'o' || p[i] == 'u'|| p[i] == 'A' || p[i] == 'E' || p[i] == 'I' || p[i] == 'O' || p[i] == 'U')    {      printf("%c",p[i]);    }   else      continue;  } return 1; } OUTPUT:  Enter the string: Malayalam The vowels in the string are: a a a ALSO READ: Sample C Program To Swap Two Strings Using strcpy() Function. Sample C Program To Sort A Given Number Of Strings Using strcmp() Function. Sample C Program To Display Array Of Strings.

Sample C Program To Accept Two Strings & Display Combination Of Two Strings.

#include<stdio.h> #include<conio.h> #include<string.h> void comb(char *p1, char *p2); void main() { char str1[10]; char str2[10]; clrscr(); printf(" \n \n Enter first string:\t "); fflush(stdin); gets(str1); printf(" \n \n Enter second string: \t "); fflush(stdin); gets(str2); comb(str1,str2); } void comb(char *p1, char *p2) { int i, l1, l2; l1 = strlen(p1); l2 = strlen(p2); printf(" \n \n The combination is: \t "); for( i = 0; i < l1; i++ )  {   printf(" %c ",p1[i]);  } for( i = 0; i < l2; i++ )  {   printf(" %c ",p2[i]);  } getch(); } OUTPUT:  Enter first string: Rahul Enter second string: Kulkarni The combination is: RahulKulkarni ALSO READ: Sample C Program To Swap Two Strings Using strcpy() Function. Sample C Program To Sort A Given Number Of Strings Using strcmp() Function. Sample C Program To Display Array Of Strings. Sample C Program To Co

Sample C Program To Accept Two Strings & Display The Largest String.

#include<stdio.h> #include<conio.h> #include<string.h> void largstr(char *p1,char *p2); void main() { char str1[10]; char str2[10]; clrscr(); printf(" \n \n Enter first string: \t "); fflush(stdin); gets(str1); printf(" \n \n Enter second string: \t "); fflush(stdin); gets(str2); largstr(str1,str2); } void largstr(char *p1, char *p2) { int l1, l2, i; l1 = strlen(p1); l2 = strlen(p2); printf(" \n \n The largest string is: \t "); if(l1 > l2)  {   for(i = 0; i < l1; i++ )    {      printf(" %c ",p1[i]);    }  } else  {   for(i = 0; i < l2; i++ )    {       printf("%c",p2[i]);    }  } getch(); } OUTPUT:  Enter first string: rahul Enter Second String: ankush The largest string is: ankush ALSO READ: Sample C Program To Swap Two Strings Using strcpy() Function. Sample C Program To Sort A Given Number Of Strings Using strcmp() Function. Sample C Program

Sample C Program To Accept A String & Display It's Alternate Characters In Reverse.

#include<stdio.h> #include<conio.h> #include<string.h> char realt(char *p); void main() { char str[10]; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); realt(str); getch(); } char realt(char *p) { int i,l; l = strlen(p); printf(" \n \n Alternate characters in reverse: \t "); for(i = l - 1; i >= 0; i -= 2)  {   printf(" %c ",p[i]);  } return 1; } OUTPUT: Enter the string: pneumonia Alternate characters in reverse: a n m e p ALSO READ: Sample C Program To Swap Two Strings Using strcpy() Function. Sample C Program To Sort A Given Number Of Strings Using strcmp() Function. Sample C Program To Display Array Of Strings. Sample C Program To Convert String To An Integer Using atoi() Function. Sample C Program To Find The Length Of A String.

Sample C Program To Accept A String & Display It's Substring.

#include<stdio.h> #include<conio.h> #include<string.h> char substr(char *p, int s, int n); void main() { char str[50]; int start,no_of_chars; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); printf(" \n \n Enter start position for substring: \t "); fflush(stdin); scanf(" %d ",&start); printf(" \n \n Enter number of characters: \t "); fflush(stdin); scanf(" %d ",&no_of_chars); substr(str,start,no_of_chars); getch(); } char substr(char *p, int s, int n) { int i; printf(" \n \n The substring is: \t "); for( i = s - 1; i < n;i++)  {   printf("%c",p[i]);  } return 1; } OUTPUT:  Enter the string: Please Mention Your Address: Enter start position for substring: 20 Enter number of characters: 7 The substring is: Address ALSO READ: Sample C Program To Swap Two Strings Using strcpy() Function. Sample C Program To Sort A Given Num

Sample C Program To Accept A String & Display Alternate Characters In Either Case.

#include<stdio.h> #include<conio.h> #include<string.h> char altcase(char *p); void main() { char str[20]; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); altcase(str); getch(); } char altcase(char *p) { printf(" \n \n Alternate characters of string are: \t "); while(*p)  {    if (*p >= 'A' && *p <= 'Z')     {       *p = *p + 32;     }    else if (*p >='a' && *p <='z')     {       *p = *p - 32;     }    printf("%c",*p);    p += 2;  } return 1; } OUTPUT:  Enter the string: LnTInfotech Alternate Characters of string are: L T n o e h ALSO READ: Sample C Program To Swap Two Strings Using strcpy() Function. Sample C Program To Sort A Given Number Of Strings Using strcmp() Function. Sample C Program To Display Array Of Strings. Sample C Program To Convert String To An Integer Using atoi() Function. Sample C Prog

Sample C Program To Accept A String & Display Its Alternate Characters.

#include<stdio.h> #include<conio.h> #include<string.h> char alt(char *p); void main() { char str[10]; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); alt(str); getch(); } char alt(char *p) { int j,l; l = strlen(p); printf(" \n \n Alternate characters of the entered string are: \t "); for(j = 0; j <= l - 1; j = j + 2)   {     printf("%c",p[j]);   } return 1; } OUTPUT: Enter the string: BODYGUARD Alternate characters of the entered string are: B D G A D ALSO READ: Sample C Program To Swap Two Strings Using strcpy() Function. Sample C Program To Sort A Given Number Of Strings Using strcmp() Function. Sample C Program To Display Array Of Strings. Sample C Program To Convert String To An Integer Using atoi() Function. Sample C Program To Find The Length Of A String.

Sample C Program To Accept A String & Display In Reverse.

#include<stdio.h> #include<conio.h> #include<string.h> char reverse(char *p); void main() { int i; char str[10]; clrscr(); printf(" \n \n Enter the String: \t "); gets(str); reverse(str); getch(); } char reverse (char *p) { int j,l; l = strlen(p); printf(" \n \n String in reverse is: \t "); for(j = l - 1; j >= 0; j--) { printf("%c",p[j]); } return 1; } OUTPUT: Enter the string: Kolaveri String in reverse is: irevalok ALSO READ: Sample C Program To Swap Two Strings Using strcpy() Function. Sample C Program To Sort A Given Number Of Strings Using strcmp() Function. Sample C Program To Display Array Of Strings. Sample C Program To Convert String To An Integer Using atoi() Function. Sample C Program To Find The Length Of A String.

Sample C Program To Accept A String & Display It.

#include <stdio.h> #include <conio.h> char string( char str2[10] ); void main() { int i; char str1[10]; clrscr(); printf(" \n \n Enter The String: \t "); for( i = 0; i <= 9; i++ )     scanf(" %c ", &str1[i] ); string( str1 ); getch(); } char string(char str2[10]) { int j; printf(" \n \n The String Is \t "); for( j = 0; j <= 9; j++ )     printf(" %c ", str2[j] ); return 1; } OUTPUT: Enter The String: Interview The String Is: Interview ALSO CHECKOUT: --  C Program To Find The Length Of A String. --  C Program To Concatenate Two Strings. --  C Program To Compare Two Strings. --  C Program To Swap Two Strings. --  C Program To Swap Two Strings Using strcpy() Function. --  C Program To Sort A Given Number Of Strings Using strcmp() Function. --  C Program To Check Whether A String Is Palindrome Or Not. --  C Program To Print The Reverse Of A String. --  C Program To J