Write a c program which prints initial of any name





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






3. Write a c program to delete the all consonants from given string.

1 comment:

kamisetty tejyapranthi said...

#include
#include
int main()
{
char str[20];
int i=0;
printf("Enter a string: ");
gets(str);
for(i=0;i<=strlen(str);i++)
{
if(i==0)
printf("%c",str[i]);
else if(str[i]==' ')
printf("%c",str[i+1]);

}
}
/*OUTPUT*/
Enter a string: Tejya Pranthi
TP