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


Please Help Members By Posting Answers For Below Questions

What is header file definition?

561


Are global variables static in c?

664


Explain what is meant by high-order and low-order bytes?

627


What is the value of uninitialized variable in c?

562


How do I get an accurate error status return from system on ms-dos?

638






List out few of the applications that make use of Multilinked Structures?

1278


Why c is called object oriented language?

574


What is the mean of function?

641


What is the scope of global variable in c?

547


What is define directive?

631


Do variables need to be initialized?

616


Why is c used in embedded systems?

599


List the difference between a While & Do While loops?

627


What will the preprocessor do for a program?

577


What are the similarities between c and c++?

589