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
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 |
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 |
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 |
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 |
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 |
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 |
Answer / dinesh balu
int i=1,a;
while(i<=20)
{
printf("%d",(a%10));
i++;
}
Is This Answer Correct ? | 10 Yes | 21 No |
Answer / dinesh balu
int i=1;
while(i<=20)
{
printf("%d",(i%10));
i++;
}
Is This Answer Correct ? | 1 Yes | 14 No |
main() { float me = 1.1; double you = 1.1; if(me==you) printf("I love U"); else printf("I hate U"); }
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)); }
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"
main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }
#define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }
what will be the position of the file marker? a: fseek(ptr,0,SEEK_SET); b: fseek(ptr,0,SEEK_CUR);
main() { int i=400,j=300; printf("%d..%d"); }
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.
Develop a routine to reflect an object about an arbitrarily selected plane
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++; } }
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
main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); } int i;