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

How do you do dynamic memory allocation in C applications?

0 Answers  


What is pointers in c?

0 Answers  


What is use of bit field?

0 Answers  


how to convert binary to decimal and decimal to binary in C lanaguage

7 Answers   BPO, Far East Promotions, IBM, RBS,


When should you not use a type cast?

0 Answers  






What's a good way to check for "close enough" floating-point equality?

0 Answers   Celstream,


What is volatile variable in c with example?

0 Answers  


What is quick sort in c?

0 Answers  


How can you increase the allowable number of simultaneously open files?

0 Answers  


main() { printf("hello%d",print("QUARK test?")); }

5 Answers  


What is hashing in c?

0 Answers  


Write a C Program to display the following menu: Menu 1. Display 2. Copy 3. Append 4. Exit Accept the choice (1-4) from the user, and perform the following tasks: Choice 1: Accept a file name from the user and display the file on screen Choice 2: Accept two file names, and copy first file to the second Choice 3: Accept two file names, and append second file to the first file Choice 4: Terminate the program

1 Answers   Accenture, Concor, DMU, Satyam, Syntel, Tora,


Categories