Professional Documents
Culture Documents
Loops
Loops
loops
1. #include<stdio.h> a. Infinite loop
int main() b. Compilation error
{ c. 0
int n=10; d. -1
for ( ; n>=0;--n); e. None of the
printf("n = %d", n); above
return 0; f. 9 8 7 6 5 4……….
}
2. #include<stdio.h> a. Compilation error
int main() b. Infinite loop
{ c. 9 7 5 3 1 -1……...
int n; d. None of the above
for (n = 9; n!=0; n--)
printf("n = %d", n--);
return 0;
}
3. #include<stdio.h>
int main()
{
int a=1; a. 1 1 1 2 2 2 3 3 3...
int b=1; b. 111
int c=1; c. Nothing will be
while(a==b==c) printed
{ d. None of the above
printf(“%d%d%d”,a,b,c);
a++;b++;c++;
}
return 0;
}
4. int main( )
{
int a; a. Compilation error
a=6; b. Bye
if(a==5); c. HelloHiBye
{ d. None of the above
printf(“Hello”);
printf(“Hi”);
}
printf(“Bye”);
}
5. int main( )
{
int a; a. Compilation error
a=5; b. hellohi
if(a==5); c. Nothing will be
printf(“hello”); printed
d. None of the above
printf(“hi”);
else
printf(“bye”);
}
6. #include<stdio.h> a. Compilation error
int main() b. 222222222...
{ c. 233333…….
int n=1; d. 12222222…….
for ( n>5;n++;n=2) e. None of the
printf("n = %d", n); above
return 0;
}
7. Write a program to reverse a number.
**
***
****
*****
Answer:
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for (i=1; i<=rows; ++i)
{
for (j=1; j<=i; ++j)
{
printf("* ");
}
printf("\n");
}
return 0;}
9. WACP to check given number is palindrome or not. ( USE
earlier reverse program and change it).
Example:
121 is palindrome