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 |
main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }
program to Reverse a linked list
12 Answers Aricent, Microsoft, Ness Technologies,
main() { struct date; struct student { char name[30]; struct date dob; }stud; struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }
You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.
main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n %u %u ",j,k); }
Extend the sutherland-hodgman clipping algorithm to clip three-dimensional planes against a regular paralleiepiped
struct Foo { char *pName; char *pAddress; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); obj->pName = malloc(100); obj->pAddress = malloc(100); strcpy(obj->pName,"Your Name"); strcpy(obj->pAddress, "Your Address"); free(obj); printf("%s", obj->pName); printf("%s", obj->pAddress); } a. Your Name, Your Address b. Your Address, Your Address c. Your Name Your Name d. None of the above
main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); }
how many processes will gate created execution of -------- fork(); fork(); fork(); -------- Please Explain... Thanks in advance..!
void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }
find A^B using Recursive function