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 / vipasha agarwal

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

Is This Answer Correct ?    0 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 / shaik musthafa

#include<stdio.h>
main()
{
int i,j=1;
for(i=1;i<=10;i++)
{
printf("%d",i);
}
j=i-2;
label:
if(j>=1)
{
printf("%d",j);
j--;
goto label;
}
}

Is This Answer Correct ?    0 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 / misha

sorry prev answer shoul say 19 instead of 20's

Is This Answer Correct ?    2 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 / ashish kapoor

I can share logic

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

}

Is This Answer Correct ?    18 Yes 21 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 / misha

int arr[20] = {1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1}
int i;

for(i = 0; i< 20; i++)
print("%d ", arr[i]);

Is This Answer Correct ?    5 Yes 8 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 / prateek jain

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

Is This Answer Correct ?    0 Yes 5 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 / ragavarajan. j

void main()
{
int i,j;
for(i=1;i<=10;i++)
{
printf("%d",i);

if(i==10)
{
i=i-1;
printf("%d",i);
}
i=i-1;
}

Is This Answer Correct ?    5 Yes 15 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 / dinesh balu

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

Is This Answer Correct ?    10 Yes 21 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 / dinesh balu

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

Is This Answer Correct ?    1 Yes 14 No

Post New Answer

More C Code Interview Questions

main() { float me = 1.1; double you = 1.1; if(me==you) printf("I love U"); else printf("I hate U"); }

1 Answers  


what is the output of the below program & why ? #include<stdio.h> void main() { int a=10,b=20,c=30; printf("%d",scanf("%d%d%d",&a,&b,&c)); }

6 Answers   CSC, IIIT,


pls anyone can help me to write a code to print the values in words for any value.Example:1034 to print as "one thousand and thirty four only"

2 Answers  


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

7 Answers  


#define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }

3 Answers  






what will be the position of the file marker? a: fseek(ptr,0,SEEK_SET); b: fseek(ptr,0,SEEK_CUR);

2 Answers  


main() { int i=400,j=300; printf("%d..%d"); }

3 Answers  


In a gymnastic competition, scoring is based on the average of all scores given by the judges excluding the maximum and minimum scores. Let the user input the number of judges, after that, input the scores from the judges. Output the average score. Note: In case, more than two judges give the same score and it happens that score is the maximum or minimum then just eliminate two scores. For example, if the number of judges is 5 and all of them give 10 points each. Then the maximum and minimum score is 10. So the computation would be 10+10+10, this time. The output should be 10 because 30/3 is 10.

0 Answers   TCS,


Develop a routine to reflect an object about an arbitrarily selected plane

0 Answers  


main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { printf(ā€œ%dā€ ,*a); a++; } p = a; for(j=0; j<5; j++) { printf(ā€œ%d ā€ ,*p); p++; } }

1 Answers  


main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error

1 Answers   HCL,


main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); } int i;

1 Answers  


Categories