about 9 years ago
This program is all about finding how many times a character comes in a string. In the program there is a count variable which will be incremented if the same character appears again and then that count variable will be printed.
- #include <stdio.h>
- int main(){
- char c[1000],char;
- int i,count=0;
- printf("Enter any string ");
- gets(c);
- printf("Enter any character whose frequency u want to find: ");
- scanf("%c",&char);
- for(i=0;c[i]!='\0';++i)
- {
- // comparing string with the character whose frequency we want to find.
- if(char==c[i])
- // increment the count variable if the same character repeated.
- ++count;
- }
- printf("Frequency of %c = %d", char, count); // printing the frequency of the character.
- return 0;
- }
#include <stdio.h> int main(){ char c[1000],char; int i,count=0; printf("Enter any string "); gets(c); printf("Enter any character whose frequency u want to find: "); scanf("%c",&char); for(i=0;c[i]!='\0';++i) { // comparing string with the character whose frequency we want to find. if(char==c[i]) // increment the count variable if the same character repeated. ++count; } printf("Frequency of %c = %d", char, count); // printing the frequency of the character. return 0; }
Output:
0 Comment(s)