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!
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 |
What is the difference between struct and typedef struct in c?
Design a program which assigns values to the array temperature. The program should then display the array with appropriate column and row headings.
If input is 123 then how to print 100 and 20 and 3 seperately?
what is the little endian and big endian?
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?
What is pointer in c?
In c programming language, how many parameters can be passed to a function ?
what is the difference between #include<> and #include”…”?
Software Interview Questions
what are the advantage of pointer variables? write a program to count the number of vowels and consonants in a given string
What are volatile variables?