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
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
why is printf("%d %d %d",i++,--i,i--);
main() { int i =0;j=0; if(i && j++) printf("%d..%d",i++,j); printf("%d..%d,i,j); }
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
Who could write how to find a prime number in dynamic array?
main() { unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
Write a program to implement the motion of a bouncing ball using a downward gravitational force and a ground-plane friction force. Initially the ball is to be projected in to space with a given velocity vector
How can i find first 5 natural Numbers without using any loop in c language????????
void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(“%d”,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(“%d”,*cptr); }
#include<conio.h> main() { int x,y=2,z,a; if(x=y%2) z=2; a=2; printf("%d %d ",z,x); }
Write a C program that defines a 2-dimentional integer array called A [50][50]. Then the elements of this array should randomly be initialized either to 1 or 0. The program should then print out all the elements in the diagonal (i.e. a[0][0], a[1][1],a[2][2], a[3][3], ……..a[49][49]). Finally, print out how many zeros and ones in the diagonal.
main() { printf("\nab"); printf("\bsi"); printf("\rha"); }
write the function. if all the character in string B appear in string A, return true, otherwise return false.