write an algorithm to get a sentence and reverse it in the
following format:
input : I am here
opuput: Here Am I
note: first letter of every word is capiatlised
Answers were Sorted based on User's Feedback
Answer / anshu ranjan
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void main()
{char *s,*t;
int i=0,j=0;
s=(char *)malloc (1000*sizeof(char));
t=(char *)malloc (50*sizeof(char));
gets(s);
i=strlen(s)-1;
while(i>=-1)
{
if(s[i]!=' ' && i>=0)
t[j++]=s[i--];
else {if(t[j-1]>=97 && t[j-1]<=122)
t[j-1]-=32;
i--;
t[j]=0;
//printf("%s ",t);
strrev(t);
printf("%s ",t);
j=0;
}
}
}
Is This Answer Correct ? | 10 Yes | 0 No |
Answer / debasis patnaik
ALGO:1.TAKE A STRING STR1
2.REVERSE IT BY STRREV(STR1)
3.CONCANICATE WITH SPACEBY STRCAT(" ",STR1)AND ASSIGN TO STR2
4.IF(STR2[I]==" ")
{
(ISUPPER(STR2[I+1])))
PRINT(STR(2)
5.END
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / vignesh1988i
here using pointers we can easily do the above..........
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
char a[50],*ptr,*pointer;
int n,i,j,k;
printf("enter the string:");
gets(a);
for(i=0;a[i]!='\0';i++)
n++;
pointer=(char*)malloc((n+1)sizeof('2'));
j=0;
for(i=0;a[i]!='\0';)
{
if(a[i]==' ')
{
*(pointer+(n-j-1))=a[i];
i++; j++;
}
else
{
ptr=&a[i];
for(k=0;a[i+1]!=' '&&a[i+1]!='\0';k++)
i++;
for(k=0;k<((&a[i]-ptr)+1);k++)
{
*(pointer+(n-j-1))=*(ptr+(&a[i]-ptr)-k);
j++;
}
}
i++;
}
*(pointer+(n+1))='\0';
for(i=0;i<n;i++)
printf("%c",*(pointer+i));
getch();
}
thank u
Is This Answer Correct ? | 1 Yes | 2 No |
What are the usage of pointer in c?
sum of two integers values only other then integer it should print invalid input.
How to create struct variables?
What is unary operator?
What is const keyword in c?
What is wrong with this declaration?
Program to swap the any two elements in an array containing N number of elements?
1 Answers Bosch, Glenwood, Ugam Solutions,
What is a char c?
What is the difference between a string and an array?
#include<stdio.h> #include<conio.h> int main() { int a[4][4]={{5,7,5,9}, {4,6,3,1}, {2,9,0,6}}; int *p; int (*q)[4]; p=(int*)a; q=a; printf("\n%u%u",p,q); p++; q++; printf("\n%u%u",p,q); getch(); return 0; } what is the meaning of this program?
What is indirection in c?
write a program to check whether a number is Peterson or not.