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 the difference between struct and typedef struct in c?

1 Answers  


Design a program which assigns values to the array temperature. The program should then display the array with appropriate column and row headings.

1 Answers  


If input is 123 then how to print 100 and 20 and 3 seperately?

4 Answers  


what is the little endian and big endian?

1 Answers  


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

1 Answers   Lovely Professional University,


Can I pass constant values to functions which accept structure arguments?

2 Answers  


What is pointer in c?

1 Answers  


In c programming language, how many parameters can be passed to a function ?

1 Answers  


what is the difference between #include<> and #include”…”?

5 Answers  


Software Interview Questions

1 Answers   CAT,


what are the advantage of pointer variables? write a program to count the number of vowels and consonants in a given string

3 Answers  


What are volatile variables?

1 Answers   Mind Tree,


Categories