write a c program which prints initial of any name | CTechnotips

C code which prints initial of any name

#include<stdio.h>
int main(){
   char str[20];
   int i=0;
   printf("Enter a string: ");
   gets(str);
   printf("%c",*str);
   while(str[i]!='\0'){
       if(str[i]==' '){
            i++;
            printf("%c",*(str+i));
       }
       i++;
   }
   return 0;
}

Sample output:

Enter a string: Robert De Niro
RDN

0 comments:

Post a Comment