Monday, June 13, 2016

C Program to count characters in given string

//Program to count characters in given string
//This program will count 'A' in given string AHMEDABAD

#include<stdio.h>
#include<string.h>
int main()
{
  char str[20]="AHMEDABAD";
  int i,cnt=0,len=0;
  
  len=strlen(str);
  
  for(i=0; i < len; i++)   {
      if( str[i] == 'A')
          cnt++;      
  } 
  printf("Total A in given string : %d",cnt);
  return 0;
}



Output:

Total A in given string : 3



* * * * *



No comments:

Post a Comment