C Programming - Strings - Discussion
Discussion Forum : Strings - Find Output of Program (Q.No. 6)
6.
What will be the output of the program If characters 'a', 'b' and 'c' enter are supplied as input?
#include<stdio.h>
int main()
{
void fun();
fun();
printf("\n");
return 0;
}
void fun()
{
char c;
if((c = getchar())!= '\n')
fun();
printf("%c", c);
}
Answer: Option
Explanation:
Step 1: void fun(); This is the prototype for the function fun().
Step 2: fun(); The function fun() is called here.
The function fun() gets a character input and the input is terminated by an enter key(New line character). It prints the given character in the reverse order.
The given input characters are "abc"
Output: cba
Discussion:
31 comments Page 4 of 4.
Sundar said:
1 decade ago
@All
In Turbo C, I have compiled the program myprogram.c and executed as given below.
C:\Turboc>myprogram.exe
kumar
ramuk
C:\Turboc>myprogram.exe
sundar kumar
ramuk radnus
C:\Turboc> _
Note: Give the input by simply typing any string and press.
The given program prints the given string in reversed order.
I hope this example will help you. Have a nice day!
In Turbo C, I have compiled the program myprogram.c and executed as given below.
C:\Turboc>myprogram.exe
kumar
ramuk
C:\Turboc>myprogram.exe
sundar kumar
ramuk radnus
C:\Turboc> _
Note: Give the input by simply typing any string and press
The given program prints the given string in reversed order.
I hope this example will help you. Have a nice day!
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers