ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
How to reverse a string using a recursive function, with
swapping?
 Question Submitted By :: Kiran
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to reverse a string using a recursive function, with swapping?
Answer
# 1
#include<stdio.h>
#include<conio.h>
char a1[50];  //GLOABAL VAR.
void reverse(int);
void main()
{
int count=0;
printf("enter the string :");
scanf("%s",a1);
for(int i=0;a1[i]!='\0';i++)
count++;
reverse(count);
getch();
}

void reverse(int count1)
{
char temp;
static int i=0;
  if(i<=count1/2)
    {
   temp=a1[i];
    a1[i]=a1[count1-1];
    a1[count1-1]=temp;
    i++;
   reverse(--count1);
    }
   else
    printf("\nthe reversed string is :%s",a1);
}




thank u
 
Is This Answer Correct ?    8 Yes 1 No
Vignesh1988i
 
  Re: How to reverse a string using a recursive function, with swapping?
Answer
# 2
the corrected code is::: 	

#include<stdio.h>
#include<conio.h>
char a1[50];  //GLOABAL VAR.
void reverse(int);
void main()
{
int count=0;
printf("enter the string :");
scanf("%s",a1);
for(int i=0;a1[i]!='\0';i++)
count++;
reverse(count);
getch();
}

void reverse(int count1)
{
char temp;
static int i=0;
  if(i!=count)
    {
   temp=a1[i];
    a1[i]=a1[count1-1];
    a1[count1-1]=temp;
    i++;
   reverse(--count1);
    }
   else
    printf("\nthe reversed string is :%s",a1);
}
 
Is This Answer Correct ?    1 Yes 3 No
Vignesh1988i
 
 
 
  Re: How to reverse a string using a recursive function, with swapping?
Answer
# 3
my next logic:::

#include<stdio.h>
#include<conio.h>
void reverse(char*,char*);
void main()
{
char a1[50],*p;
int count=0;
printf("enter the string:");
scanf("%s",a1);
for(int i=0;a[i]!='\0';i++)
count++;
p=a1+(count-1);
reverse(a1,p);
printf("the reversed one is : %s",a1);
getch();
}
void reverse(char *a1,char *p)
{
char temp;
if(a1<=p)
{
temp=*a1;
*a1=*p;
*p=temp;
reverse(++a1,--p);
}
}




thank u
 
Is This Answer Correct ?    1 Yes 0 No
Vignesh1988i
 
  Re: How to reverse a string using a recursive function, with swapping?
Answer
# 4
#include<stdio.h>
#include<string.h>
char s1[50];
void reverse();
int main()
{
        scanf("%s",s1);
        reverse();
        return 0;
}
void reverse()
{
        char temp;
        int n=strlen(s1);
        static int i=0;
        if (i<n/2)
                {
                temp=s1[n-i-1];
                s1[n-i-1]=s1[i];
                s1[i]=temp;
                i++;
                reverse();
                }
                else
                printf("The reverse string is %s\n",s1);
}
~
 
Is This Answer Correct ?    2 Yes 0 No
Kamrul Islam
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is the difference between const char *p, char const *p, const char* const p Accenture4
7. Identify the correct argument for the function call fflush() in ANSI C: A)stdout B)stdin C)stderr D)All the above Accenture8
How to receive strings with spaces in scanf()  4
why TCS selected more student in the software field from all institution. TCS3
what is real time system?what is the differance between hard and soft real time systems  2
DIFFERNCE BETWEEN THE C++ AND C LANGUAGE? Wipro2
how to implement stack operation using singly linked list  1
1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collision Qualcomm6
Here is alphabets : abcdefgh 1) how to reverse. as hgfedcba 2) after reversal, how to group them in a pair hg fe dc ba.  2
Given an unsigned integer, find if the number is power of 2?  3
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it?  3
How to implement call back functions ? HP2
5. distance conversion: Convert a distance from miles to kilometers .there are 5280 feets per mile,12 inches per foot .2.54 centimeters per inch and 100000centimeters per kilometer  1
f=(x>y)?x:y a) f points to max of x and y b) f points to min of x and y c)error HCL4
given the piece of code int a[50]; int *pa; pa=a; to access the 6th element of the array which of the following is incorrect? a.*(a+5) b.a[5] c.pa[5] d.*(*pa + 5) TCS5
without using arithmatic operator convert an intger variable x into x+1  1
how can i make a program with this kind of output.. Enter a number: 5 0 01 012 0123 01234 012345 01234 0123 012 01 0 Wipro3
if a person is buying coconuts of Rs10,and then sell that coconuts of Rs9,with the loss of one rupee.After that the person became a millaniore.how? Wipro5
What kind of sorting is this? SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort Accenture3
Write an implementation of “float stringToFloat(char *str).” The code should be simple, and not require more than the basic operators (if, for, math operators, etc.). • Assumptions • Don’t worry about overflow or underflow • Stop at the 1st invalid character and return the number you have converted till then, if the 1st character is invalid return 0 • Don’t worry about exponential (e.g. 1e10), instead you should treat ‘e’ as an invalid character • Write it like real code, e.g. do error checking • Go though the string only once • Examples • “1.23” should return 1.23 • “1a” should return 1 • “a”should return 0 Qualcomm5
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com