Just came across this question, felt worth sharing, so here
it is
I want you to make a C/C++ program that for any positive
integer n will print all the positive integers from 1 up to
it and then back again!
Let's say n=5 I want the program to print: 1 2 3 4 5 4 3 2 1.
Too easy you say?
Okay then... You can ONLY USE:
1 for loop
1 printf/cout statement
2 integers( i and n)
and as many operations you want.
NO if statements, NO ternary operators, NO tables, NO
pointers, NO functions!



Just came across this question, felt worth sharing, so here it is I want you to make a C/C++ progr..

Answer / manohar reddy

int main()
{
int i, j;
for(i = 1, j = 0;j < 9;j++, i += int(j/5)*-2 + 1)
printf("%d ",i);
}

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More C Interview Questions

What is FIFO?

0 Answers  


Write a program to enter the name and age. If age>28 then find salary categories. if age<28 then find that you are gaduate or not.

1 Answers  


explain memory layout of a C program

2 Answers  


how to find the largest element of array without using relational operater?

6 Answers   Satyam, Wipro,


how to swap 2 numbers within a single statement?

4 Answers  






Why do u use # before include in a C Progam?

9 Answers   IBM,


Explain the ternary tree?

0 Answers  


#include<stdio.h> int main() { int a[3][3][2]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18}; printf("%d\n",*(*(*a+1)); return 0; } What will be the output of the above question? And how?

1 Answers   Groupon,


which operator is known as dummy operator in c?

2 Answers   Wipro,


praagnovation

0 Answers  


write a program to find the frequency of a number

4 Answers   Infosys,


Are bit fields portable?

0 Answers   EXL,


Categories