You are on page 1of 3

School of Computer Engineering, PROGRAMMING IN C

KIIT University, Bhubaneswar (Looping: while, do..while, for), break, continue, goto

Looping (SHORT TYPE)


3.7 Write the output of the following code
3.1 Give examples of entry controlled loops and void main( )
exit controlled loops. {
3.2 Differentiate int x=20;
a) while and do..while do{
b) break and continue printf(“%d”, x);
c) goto and for x++;
3.3 How many times the following for loop-body }while(x<20);
will be executed? }
int x;
for(i = -3;i<=50;i++) 3.8 What is the output of the following program?
i *= -8; void main()
{
3.4 How many times "Welcome" will be printed? int i, j;
#include<stdio.h> for(i=1; i<5; i++)
int main() {
{ for(j=1; j<5; j++)
int x; if(i%j!=0) break;
for(x=-1; x<=10; x++) printf(“%d ”,i+j);
{ }
if(x<5) }
continue;
else 3.9 What is the output of the following program?
break; void main()
printf("Welcome"); {
} int i, j;
return 0; for(i=1; i<5; i++)
} {
for(j=1; j<5; j++)
3.5 What would be the output of the following if(i%j==0) break;
program segment? printf(“%d ”,i+j);
int k=3; }
while(k<100) }
{
printf(“\t%d”,k); 3.10 Write the output of the following code
k=k*7; void main()
} {
printf("\t%d",k); int x=0, i=1,j=2;
for(i=0;i<5;i++)
3.6 What would be the output of the following for(j=0;j<I;j++)
program segment? {
void main( ) x+=i+j;
{ printtf("%d",x);
int i ; }
for (i=27; i>0; i=i/2) printf("\n%d",x);
printf ("%d", i%2); }
}

KIIT/CS 1001: Programming in C (PC) Home Assignments Page 1


School of Computer Engineering, PROGRAMMING IN C
KIIT University, Bhubaneswar (Looping: while, do..while, for), break, continue, goto

3.11 What will be the output of the following C (except for the order). These are called prime
program? Justify. factors of a number. In other words, In
int main () number theory, the prime factors of a positive
{ integer are the prime numbers that divide that
int i=0, x=0; integer exactly, without leaving a remainder.
for (i=1 ; i<10; i * =2) The process of finding these numbers is called
{ x++; integer factorization, or prime factorization.
printf ("%d", x); - Enter a number : 100
} - The prime factors of 100 are 2(2) and 5(2)
printf ("n x=%d", x); , that is, 100 = 2 x 2 x 5 x 5, and those
} numbers are primes.)
3.22 WAP to find the first n numbers of a
3.12 Write the output of the following code. Fibonacci sequence.
void main() { 3.23 WAP to evaluate the equation y=xn where n is
int i; a non-negative integer.
for(i=0; i<=2; i++);{ 3.24 WAP to print the series as 1 2 7 15 31
printf("%d",i); ..........n, where n is given by user.
printf("Bhubaneswar"); } 3.25 WAP to print the series as 1 1 2 3 5 8 13
printf("India"); } ..........n, where n is given by user.
3.26 WAP to print the series as 3 5 7 11 13
Looping (LONG TYPE) 17..........n, where n is given by user.
3.27 Write a C program to evaluate the following
WAP stands for Write a program series
1+ 1/2!+2/3!+3/4!+⋯+n/((n+1)!)… where
3.13 WAP to calculate the factorial of a given n is a user input.
number. 3.28 WAP to print all odd and even numbers
3.14 WAP to calculate the sum of digits of a given separately within a given range. The range is
number. input through user.
3.15 WAP to display the reverse of a number 3.29 WAP to calculate sum of squares of first n
entered through keyboard. odd numbers.
3.16 WAP to find the GCD/HCF of two numbers . 3.30 WAP to convert a decimal number into its
3.17 WAP to check whether a number n is prime equivalent binary number.
number or not. 3.31 WAP to convert a binary number into its
3.18 WAP to check whether an input integer is equivalent decimal number.
perfect number or not. 3.32 WAP to print the following pattern for n rows.
3.19 WAP to check whether an integer number is a Ex. for n=5 rows
Armstrong number or not!. A
3.20 WAP to check whether an input integer is A B
strong number or not. A B C
(Hint: If the sum of factorials of all digits of a A B C D
number are equal to the number are equal to A B C D E
the number, it is called a strong number )
3.21 WAP to find out the prime factors of a
number entered through keyboard (distinct).
(Hints: A prime number is any number with
no divisors other than itself and 1, such as 2
and 5. Any number can be written as a
product of prime numbers in a unique way

KIIT/CS 1001: Programming in C (PC) Home Assignments Page 2


School of Computer Engineering, PROGRAMMING IN C
KIIT University, Bhubaneswar (Looping: while, do..while, for), break, continue, goto

3.33 WAP to print the following pattern for n rows.


Ex. for n=5 rows 3.39 WAP to generate the pascal triangle pyramid
of numbers for a given number.
A Ex. for number 4
B A 1
C B A 1 1
D C B A 1 2 1
E D C B A 1 3 3 1
1 4 6 4 1
3.34 WAP to print the following pattern for n rows.
Ex. for n=5 rows 3.40 Write a program to display the numbers in the
1 following format
2 1 1 1
1 2 3 1 2 1 2
4 3 2 1 1 2 3 1 2 3
1 2 3 4 5 1 2 3 4 1 2 3 4

3.35 WAP to form a pyramid of numbers for a


given number. Ex. for number 4
1
121
12321
1234321

3.36 WAP to form reverse pyramid of numbers for


a given number. Ex. for number 4
1234321
12321
121
1
3.37 WAP to print the following pattern for n rows.
Ex. for n=6 rows
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
0 1 0 1 0 1

3.38 WAP to print the following pattern for n rows.


Ex. for n=6 rows
0
1 0
0 1 0
1 0 1 0
0 1 0 1 0
1 0 1 0 1 0

KIIT/CS 1001: Programming in C (PC) Home Assignments Page 3

You might also like