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

write a program in c to find out the sum of digits of a number.but here is a condition that compiler sums the value from left to right....not right to left..

1 Answers  


Describe wild pointers in c?

0 Answers  


What are register variables? What are the advantage of using register variables?

0 Answers   TISL,


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

0 Answers   HP,


How do you determine a file’s attributes?

0 Answers  






ATM machine and railway reservation class/object diagram

0 Answers   Zycus Infotech,


Why is #define used?

0 Answers  


what is mallloc()?how it works?

4 Answers   Excel,


Explain bit masking in c?

0 Answers  


What is the use of linkage in c language?

0 Answers  


What are structural members?

0 Answers  


Hi can anyone tell what is a start up code?

0 Answers   CTS,


Categories