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



write an algorithm to get a sentence and reverse it in the following format: input : I am here op..

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

write an algorithm to get a sentence and reverse it in the following format: input : I am here op..

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

write an algorithm to get a sentence and reverse it in the following format: input : I am here op..

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

Post New Answer

More C Interview Questions

What is nested structure?

0 Answers  


What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

0 Answers   Aspire, Infogain,


What would be an example of a structure analogous to structure c?

0 Answers  


Is there sort function in c?

0 Answers  


How do you list a file’s date and time?

0 Answers  






What are different types of variables in c?

0 Answers  


Describe the steps to insert data into a singly linked list.

0 Answers  


write program on arrays

3 Answers   GE, Polycab,


Explain what are reserved words?

0 Answers  


How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls answer it.. Thanks in Advance

8 Answers  


What does s c mean in text?

0 Answers  


Program to simulate second clock

2 Answers  


Categories