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 |
Write a program in c to print 1 121 12321 1234321 123454321
11 Answers ANR, College School Exams Tests, Mu Sigma, Wipro,
1 What is a Data Structure?
How do you define CONSTANT in C?
C language questions for civil engineering
WHAT IS RTGS N MINIMUM AMT TO B TRANSFERD N WHAT R THE CHARGES ON MINIMUM AMT N IN WHICH BANK WE CAN DO IT?
What is variable declaration and definition in c?
What is a sequential access file?
explain how do you use macro?
What are the different data types in C?
What are actual arguments?
What does *p++ do?
What is use of integral promotions in c?