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 |
difference between semaphores and mutex?
What is getche() function?
what is the height of tree if leaf node is at level 3. please explain
how the compiler treats any volatile variable?Explain with example.
how can i get the string which is having two spaces at the end.suppose the string is "Hello World ".Now at the end i have two spaces.i need to print with that spaces .
write a function that accepts an array A with n elements and array B with n-1 elements. Find the missing one in array B,with an optimized manner?
How can I call fortran?
what does " calloc" do?
Is it better to bitshift a value than to multiply by 2?
What are the average number of comparisons required to sort 3 elements?
what is reason of your company position's in india no. 1.
print the pattern 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 if n=5