Вы находитесь на странице: 1из 3

School of Computer Engineering,

KIIT University, Bhubaneswar

Looping

PROGRAMMING IN C
(Looping: while, do..while, for), break, continue, goto

(SHORT TYPE)

3.1 Give examples of entry controlled loops and


exit controlled loops.
3.2 Differentiate
a) while and do..while
b) break and continue
c) goto and for
3.3 How many times the following for loop-body
will be executed?
int x;
for(i = -3;i<=50;i++)
i *= -8;
3.4 How many times "Welcome" will be printed?
#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x<5)
continue;
else
break;
printf("Welcome");
}
return 0;
}
3.5 What would be the output of the following
program segment?
int k=3;
while(k<100)
{
printf(\t%d,k);
k=k*7;
}
printf("\t%d",k);
3.6 What would be the output of the following
program segment?
void main( )
{
int i ;
for (i=27; i>0; i=i/2)
printf ("%d", i%2);
}
KIIT/CS 1001: Programming in C (PC) Home Assignments

3.7 Write the output of the following code


void main( )
{
int x=20;
do{
printf(%d, x);
x++;
}while(x<20);
}
3.8 What is the output of the following program?
void main()
{
int i, j;
for(i=1; i<5; i++)
{
for(j=1; j<5; j++)
if(i%j!=0) break;
printf(%d ,i+j);
}
}
3.9 What is the output of the following program?
void main()
{
int i, j;
for(i=1; i<5; i++)
{
for(j=1; j<5; j++)
if(i%j==0) break;
printf(%d ,i+j);
}
}
3.10 Write the output of the following code
void main()
{
int x=0, i=1,j=2;
for(i=0;i<5;i++)
for(j=0;j<I;j++)
{
x+=i+j;
printtf("%d",x);
}
printf("\n%d",x);
}
Page 1

School of Computer Engineering,


KIIT University, Bhubaneswar

PROGRAMMING IN C
(Looping: while, do..while, for), break, continue, goto

3.11 What will be the output of the following C


program? Justify.
int main ()
{
int i=0, x=0;
for (i=1 ; i<10; i * =2)
{ x++;
printf ("%d", x);
}
printf ("n x=%d", x);
}
3.22
3.12 Write the output of the following code.
void main() {
int i;
for(i=0; i<=2; i++);{
printf("%d",i);
printf("Bhubaneswar"); }
printf("India"); }

3.23
3.24
3.25
3.26

Looping

(LONG TYPE)

3.27

WAP stands for Write a program


3.13 WAP to calculate the factorial of a given
number.
3.14 WAP to calculate the sum of digits of a given
number.
3.15 WAP to display the reverse of a number
entered through keyboard.
3.16 WAP to find the GCD/HCF of two numbers .
3.17 WAP to check whether a number n is prime
number or not.
3.18 WAP to check whether an input integer is
perfect number or not.
3.19 WAP to check whether an integer number is a
Armstrong number or not!.
3.20 WAP to check whether an input integer is
strong number or not.
(Hint: If the sum of factorials of all digits of a
number are equal to the number are equal to
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

3.28

3.29
3.30
3.31
3.32

(except for the order). These are called prime


factors of a number. In other words, In
number theory, the prime factors of a positive
integer are the prime numbers that divide that
integer exactly, without leaving a remainder.
The process of finding these numbers is called
integer factorization, or prime factorization.
- Enter a number : 100
- The prime factors of 100 are 2(2) and 5(2)
, that is, 100 = 2 x 2 x 5 x 5, and those
numbers are primes.)
WAP to find the first n numbers of a
Fibonacci sequence.
WAP to evaluate the equation y=xn where n is
a non-negative integer.
WAP to print the series as 1 2 7 15 31
..........n, where n is given by user.
WAP to print the series as 1 1 2 3 5 8 13
..........n, where n is given by user.
WAP to print the series as 3 5 7 11 13
17..........n, where n is given by user.
Write a C program to evaluate the following
series
1+ 1/2!+2/3!+3/4!++n/((n+1)!)
where
n is a user input.
WAP to print all odd and even numbers
separately within a given range. The range is
input through user.
WAP to calculate sum of squares of first n
odd numbers.
WAP to convert a decimal number into its
equivalent binary number.
WAP to convert a binary number into its
equivalent decimal number.
WAP to print the following pattern for n rows.
Ex. for n=5 rows
A
A B
A B C
A B C D
A B C D E

Page 2

School of Computer Engineering,


KIIT University, Bhubaneswar

PROGRAMMING IN C
(Looping: while, do..while, for), break, continue, goto

3.33 WAP to print the following pattern for n rows.


Ex. for n=5 rows
A
B
C
D
E

A
B A
C B A
D C B A

3.34 WAP to print the following pattern for n rows.


Ex. for n=5 rows
1
2 1
1 2 3
4 3 2 1
1 2 3 4 5

3.39 WAP to generate the pascal triangle pyramid


of numbers for a given number.
Ex. for number 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
3.40 Write a program to display the numbers in the
following format
1
1
1 2
1 2
1 2 3
1 2 3
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

Вам также может понравиться