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 Posted / 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 View All Answers
What is a void pointer? When is a void pointer used?
Why is sprintf unsafe?
Explain data types & how many data types supported by c?
Differentiate between declaring a variable and defining a variable?
can any one provide me the notes of data structure for ignou cs-62 paper
Please send me WIPRO technical question to my mail ID.. its nisha_g28@yahoo.com please its urgent
What is the difference between #include
What is oops c?
How do you determine the length of a string value that was stored in a variable?
How can I direct output to the printer?
Explain the advantages and disadvantages of macros.
What is the full form of getch?
application attempts to perform an operation?
What is a program flowchart and how does it help in writing a program?
What happens if header file is included twice?