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 is the output of the code and how? main() { int *ptr,x; x=sizeof(ptr); printf("%d",x); }
write an interactive C program that will encode or decode a line of text.To encode a line of text,proceed as follows. 1.convert each character,including blank spaces,to its ASCII equivalent. 2.Generate a positive random integer.add this integer to the ASCII equivalent of each character.The same random integer will be used for the entire line of text. 3.Suppose that N1 represents the lowest permissible value in the ASCII code,and N2 represents the highest permissible value.If the number obtained in step 2 above(i.e.,the original ASCII equivalent plus the random integer)exceeds N2,then subtract the largest possible multiple of N2 from this number,and add the remainder to N1.Hence the encoded number will always fall between N1 and N2,and will therefore always represent some ASCII character. 4.Dislay the characters that correspond to the encoded ASCII values. The procedure is reversed when decoding a line of text.Be certain,however,that the same random number is used in decodingas was used in encoding.
Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 1. Print only the alphabets . If in upper case print in lower case vice versa.
Method Overloading exist in c ?
Is c an object oriented programming language?
write a program in c to read array check element is present or not?
using for loop sum 2 number of any 4 digit number in c language
my name is nani i completed my b-tech in hyd now i want go for interveiw but i dont know the process of software field interveiws plz help me anyone how many rouds there n what rounds plz plz plz help me n where i can get these details
char *p="name"; printf(p);
the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?
What is the use of function in c?
Write a program to generate the first n terms in the series --- 2,3,5,7,11,...,17