Q. Write a C program to accept a string from user and put the first character of word at the end of string and add one extra character.
Example:
Enter String: This Is A Good Blog
Result: hisTX sIX AX oodGX logBX
Ans.
/*c program for taking first character of every word and put it at the end of word and then add one extra word.*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char tmp,str[30];
int i;
printf("Enter string : ");
gets(str);
printf("\n-- Result of program --\n\n");
tmp=str[0];
for(i=1; str[i]!='\0'; i++)
{
if(str[i]==' ')
{
printf("%cX",tmp);
printf(" ");
i++;
tmp=str[i];
}
else
printf("%c",str[i]);
}
printf("%cX",tmp);
getch();
return 0;
}
/***************Output*****************/
Related program:
Example:
Enter String: This Is A Good Blog
Result: hisTX sIX AX oodGX logBX
Ans.
/*c program for taking first character of every word and put it at the end of word and then add one extra word.*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char tmp,str[30];
int i;
printf("Enter string : ");
gets(str);
printf("\n-- Result of program --\n\n");
tmp=str[0];
for(i=1; str[i]!='\0'; i++)
{
if(str[i]==' ')
{
printf("%cX",tmp);
printf(" ");
i++;
tmp=str[i];
}
else
printf("%c",str[i]);
}
printf("%cX",tmp);
getch();
return 0;
}
/***************Output*****************/
Screen shot for reverse each first character of word and adding one extra word C program |
Related program:
No comments:
Post a Comment