Friday, February 5, 2016

C program to print initial of given name

#include<stdio.h>
int main()
{
  char str[20];
  int i=0;
  printf("Enter a string: ");
  gets(str);

  printf("%c",str[0]);
  while(str[i]!='\0')
  {
if(str[i]==' ')
{
     i++;
     printf("%c",str[i]);
}
i++;
  }
 return 0;
}

Output of program

Enter a string: ABC PATEL
AP



No comments:

Post a Comment