how to print
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
using any loop(for or while) only once(only 1 loop) and
maximum 2 variables using C.

Answers were Sorted based on User's Feedback



how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1..

Answer / santhanasamy

int i = 1,j=1;
do
{
printf("%d",i);
if (j<10)
i++;
else
i--;
j++;
}while(j<20);

Is This Answer Correct ?    63 Yes 9 No

how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1..

Answer / ajay karanam

int main()
{
int b=0,a=20;
for(b=0;b<20;b++,a--)
{
if(b>a)
{
printf("%d\n",a);
}
else if(b<a)
{
printf("%d\n",b+1) ;
}
}
return 0;
}

Is This Answer Correct ?    7 Yes 2 No

how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1..

Answer / deva

void main()
{
int a = 1, b = 9;

for(;a <= 10 || b >= 1;)
{
if( a <= 10)
{
printf("%d ", a++);
}
else if(b >= 1)
{
printf("%d ", b--);

}
}
}

Is This Answer Correct ?    7 Yes 3 No

how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1..

Answer / prasad

int i=1,j=9;
while(i<=20)
{
if(i<=10)
{
printf("%d ",i);
i++;
}
else
{
printf("%d ",j);

j--;
}

if(j==0)
break;

}

Is This Answer Correct ?    5 Yes 1 No

how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1..

Answer / chand

main()
{
int j=0,i=1;
for(i;i<20;i++)
{
if(i<=10)
{
j++;
printf("%d",i);
}
else if(j<=10)
{
j--;
printf("%d",j);
}
}

Is This Answer Correct ?    4 Yes 1 No

how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1..

Answer / sanjay bhosale

int i=1,a=1;
while(i<20)
{
if(i<10)
printf("\t%d",a++);
else if(i==10)
printf("\t%d",a);
else
printf("\t%d",--a);
i++;
}

Is This Answer Correct ?    3 Yes 0 No

how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1..

Answer / taizul

#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
for(int i = 1; i < 20; i++){
if(i>=10){
printf("%d ",(10-(i%10)));

}
else{
printf("%d ",i);
}

}
return 0;
}

Is This Answer Correct ?    2 Yes 0 No

how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1..

Answer / joteen patro

void f1(int i);
void f2(int i);
void main()
{
int i=1;
while(i>0)
{
if(i<=10)
f1(i);
if(i==10)
f2(i);
}
}
void f1(int i)
{
if(i<10){
printf("%d",i);
f1(i++);
}
else
break;
}
void f2(int i)
{
if(i>0)
{
printf("%d",i);
f2(i--)
}
else
break;
}

Is This Answer Correct ?    1 Yes 0 No

how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1..

Answer / boleto

int main(void)
{

int i,j=1;

for(i=10;i>1;)
{
if(j<=10)
{
printf("%d ",j++);
}
else
{
printf("%d ",i--);
}
}

return 0;
}

Is This Answer Correct ?    2 Yes 2 No

how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1..

Answer / apsita surana

#include<stdio.h>
void main()
{
int i,j; //two variables
for(i=1,j=9;i<=19;i++)
{
if(i<=10)
{
printf("%d ",i);}
else
{
printf("%d",j);
j--;
}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Code Interview Questions

{ int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

4 Answers  


main() { char a[4]="HELLO"; printf("%s",a); }

3 Answers   CSC,


main() { signed int bit=512, mBit; { mBit = ~bit; bit = bit & ~bit ; printf("%d %d", bit, mBit); } } a. 0, 0 b. 0, 513 c. 512, 0 d. 0, -513

3 Answers   HCL, Logical Computers,


Write a function to find the depth of a binary tree.

13 Answers   Adobe, Amazon, EFI, Imagination Technologies,


main() { int i=0; while(+(+i--)!=0) i-=i++; printf("%d",i); }

9 Answers   CSC, GoDB Tech, IBM,






To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

0 Answers  


How to return multiple values from a function?

7 Answers  


What is "far" and "near" pointers in "c"...?

3 Answers  


How to swap two variables, without using third variable ?

104 Answers   AB, ADP, BirlaSoft, Cisco, Cygnet Infotech, HCL, Hewitt, Honeywell, HP, IBM, Infosys, Manhattan, Microsoft, Mobius, Percept, Satyam, SofTMware, TCS, Wipro, Yamaha,


enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }

2 Answers  


Write a C program to add two numbers before the main function is called.

11 Answers   Infotech, TC,


main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }

1 Answers  


Categories