Thursday, February 4, 2016

C program to count A in a given string.

#include<stdio.h>
int main()
{
char str1[80]="WE ARE IN AHMEDABAD";
int i, A_counter=0;

printf("Given String = %s",str1);

for(i=0; i<strlen(str1); i++)
{
if(str1[i] == 65) //65 is ascii value of A
A_counter = A_counter + 1;
}
printf("\nTotal 'A' in the given string is %d", A_counter );
 return 0;
}

Output of program

Given String = WE ARE IN AHMEDABAD
Total 'A' in the given string is 4


No comments:

Post a Comment