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 recursion in C
void main() { int *ptr; ptr = (int *) 0x400 ; printf("ptr=%d",ptr); } output?
What is size of union in c?
Why do we use namespace feature?
how can make variable not in registers
what is the code to display color fonts in the output?
What is a pointer variable in c language?
5 Write an Algorithm to find the maximum and minimum items in a set of ‘n’ element.
what is available in C language but not in C++?
10 Answers CTS, TCS,
Sir,please help me out with the output of this programme:- #include<stdio.h> #include<conio.h> void main() { int a=18,b=12,i; for(i=a<b?a:b;a%i||b%i;i--); printf("%d %d",i); }
What will be the result of the following C language program? main() { int a = 0; int b = 20; char x = 1; char y = 10; if(a,b,x,y) printf("Welcome"); }
Explain the difference between getch() and getche() in c?