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

discuss the steps needed to get a program from source code to executable in a system?

1 Answers  


What is the difference between memcpy and memmove?

0 Answers  


. Write a program to get a string and to convert the 1st letter of it to uppercase

2 Answers   HTC,


What do you mean by keywords in c?

0 Answers  


FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

0 Answers  






write a c program thal will find all sequences of length N that produce the sum is Zero, print all possible solutions?

0 Answers   Wipro,


Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates

3 Answers  


identify the in correct expression a.a=b=3=4; b.a=b=c=d=0; float a=int b=3.5; d.int a; float b; a=b=3.5;

8 Answers   TCS,


write a program to find a given no. is divisible by 3 or not without using any arthimetic operators?

3 Answers   Broadcom, TCS,


What is the difference between %d and %i?

0 Answers  


What is header file in c?

0 Answers  


how to print 2-D array using a single for loop?

2 Answers   Mind Tree, TCS, Value Labs,


Categories