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 indirection in c?
write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?
main() { int ptr[] = {1,2,23,6,5,6}; printf("%d",&ptr[3]-&ptr[0]); }
What are file streams?
Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.
How can we see the Expanded source code and compiled code for our source program in C?
what is the output of the following code? main() { int I; I=0x10+010+10; printf("x=%x",I); } give detailed reason
What is the value of a[3] if integer a[] = {5,4,3,2,1}?
What is the difference between getch() and getche()?
how to convert an char array to decimal array
If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..
The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration