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() { extern int i; i=20; printf("%d",sizeof(i)); }
Write a C function to search a number in the given list of numbers. donot use printf and scanf
main() { int c = 5; printf("%d", main||c); } a. 1 b. 5 c. 0 d. none of the above
void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above
#include<stdio.h> int main() { int a=3,post,pre; post= a++ * a++ * a++; a=3; pre= ++a * ++a * ++a; printf("post=%d pre=%d",post,pre); return 0; }
main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }
main() { while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”); }
main() { float i=1.5; switch(i) { case 1: printf("1"); case 2: printf("2"); default : printf("0"); } }
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++; } }
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.
Write a procedure to implement highlight as a blinking operation
main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); } int i;