Professional Documents
Culture Documents
1
is the statement within the if construct given below executed?
Why or why not?
1 = 1;
If ( - - 1= 0)
Printf ( Executed! \ n ) ;
2
write a program to accept a string and an integer, and
print the string as many times as the value of the integer this
procedure should continue until the user presses q to quit ?
3 Explain the difference between while and do while loops with
respect to the minimum number of times the body of the loop is
executed.
4 write a program that accepts a number from 0 to 9 along with a
string to be displayed a specified number of times. Use the switch
case construct. ?
5 write a program to accept characters until q is pressed Display
each character immediately after it is accepted. Also store the
characters in an array, to be displayed before the program
terminates.
6 Explain the significance of the break statement in the switch case
construct what would result in its absence?
7 write a program that accepts 0, 1, or 2 if 0 is entered by the user,
accept the necessary parameters (radius height, etc.) to calculate
the volume of a cylinder inputs 1 and 2 correspond to cylinder and
cone, respectively. Note that the above process must go on until the
user enters q to terminate the program [Hint: use a switch case
construct within a while or do while loop]
8 when is the default keyword useful in a switch case construct?
Modify the program written for question 6 so that an error message
is displayed whenever an input other than 0, 1 or 2 is entered.
9 modify the sample programs given in this chapter by replacing a
while loop by a for loop and vice- versa?
10 write a program to generate the first hundred tems of the
Fibonacci series and print their sum and average?
if (sum % 5 = = 0)
break ;
}
Rewrite the statements using a do while construct. Do not use the
break statement.
Dose it make any difference if you input all numbers on a single
line separated by spaces or input them by pressing the enter key
after each number?
20A break statement is used to exit a loop or a switch case
structure. What happens if the break
Statement is used outside any such construct? Differentiate
between the break and continue statement ?
Exercises
9 write a program using conditional operators to determine
whether a year entered through the keyboard is a leap year or not.
10 the factorial of an integer n is the product of consecutive integer
from 1 to n. that is factorial n = n ! = n x ( n-1) x (n-3) xx 3 x2
x1. write a C program to find the factorial value of n.
11 write a C program to print the quotient of an integer number
without using / .
12 write a program to print all the even and odd numbers of a
certain range as indicated by the user.
13 write a C program to convert the binary equivalent of an integer
number without using array.
14 write a C program to find the prime factors of a number given
by the user.
(ii) *
**
***
* * * * up to nth line
(iii) 1
12
123
1234 up to nth line
(v)
1
22
333
4444
5 5 5 5 5 up to nth line
ARRAY
PROGRAMMING
1). Write C program for the following
a)
any), and the title as it is, e.g. , Raj kumar santoshi as R.K.
santoshi.
30. write a C program that reads a line of text and counts all
occurrences of a particular word.
31. Write a program to convert each character of a string into
the next alphabet and print the string.
32. Write a program that accepts a word from the user and
prints it in the following way. For example, if the word is
COMPUTER, the program will print it as
C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
COMPUTER