Here is alphabets : abcdefgh
1) how to reverse. as hgfedcba
2) after reversal, how to group them in a pair hg fe dc ba.

Answers were Sorted based on User's Feedback



Here is alphabets : abcdefgh 1) how to reverse. as hgfedcba 2) after reversal, how to group them i..

Answer / srinivas

1)Ans:
its simple find the string length say K
now run a a loop from 0 to K/2 incrementing by 1 every time
and swap the elements as
for(i=0;i<K/2;i++)
{
temp=a[i];
a[i]=a[K-(i+1)]
a[K-(i+1)]=temp;
}/*this is to reverse the string*/
2)Ans:
for(i=0;i<K;i++)
{
printf("%c",a[i]);
if((i+1)%2==0)
printf(" ");
}/*this is for printing in groups*/

Is This Answer Correct ?    4 Yes 0 No

Here is alphabets : abcdefgh 1) how to reverse. as hgfedcba 2) after reversal, how to group them i..

Answer / ruchi

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
int i,c;
char p[]="abcdefgh";
i=strlen(p);
for(c=i;c>=0;c--)
{
printf("%c",p[c]);
}
for(c=i;c>=0;c--)
{
printf("%c",p[c]);
if(c%2==0)
{
printf(" ");
}
}
getch();
}

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More C Interview Questions

Explain how can I pad a string to a known length?

0 Answers  


main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }

0 Answers   Wilco,


What is the collection of communication lines and routers called?

0 Answers  


how to make a scientific calculater ?

0 Answers  


Which header file is essential for using strcmp function?

0 Answers  






main() { int i; printf("%d",((i=1)*i-- - --i*(i=-3)*i++ + ++i)); } ans is 24 bt how?pls tell smbody............

3 Answers  


Did c have any year 2000 problems?

0 Answers  


Can you explain the four storage classes in C?

0 Answers   TCS,


What is the difference between far and near in c?

0 Answers  


what do you mean by inline function in C?

0 Answers   IBS, TCS,


main() { static char *s[]={"black","white","yellow","voilet"}; char **ptr[]={s+3,s+2,s+1,s}, ***p; p=ptr; **++p; printf("%s",*--*++p+3); }

1 Answers  


Who is invented by c?

24 Answers   Infosys, Mphasis,


Categories