Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C-Loops and Control Statement-7

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

LOOPs and Basic control statements

1 Calculate n! (i.e. n factorial) where


a. if n>0 then n! = 1*2*3*4*5…*n
b. n=0 then n!=1
c. n<0 then n! is not defined

2. Check whether given number is Armstrong or not? [Armstrong number


means sum of cube of digits is equivalent to number itself. E.g. 153 is an
Armstrong number.]

3. Print Fibonacci series: - 1,1,2,3,5,8,13… (Hint: After the first two numbers
in the series, each number is the sum of the two preceding numbers.)

4. .Wap To read integers (until user enters 0 to stop); find sum, average, max
and min of these integers added by user.

5. Determine and print the sum of the following harmonic series for a
given value of n:
a. 1 + ½ + 1/3 + ¼ +. …+ 1/n
b. Given that PI = 4(1-1/3+1/5+1/9+1/14+…)
Write a program to evaluate the value of PI as the sum of 10 terms or
20 terms ,… or 100-terms and print as per the following format
c. No. of Terms | Value of PI
d. --------------------------------------
e. <<your ans>>
f. <<your ans>>
g. . .
h. . .
i. . .
j. <<your ans>>
k. *

6. Witnesses at the scene of a crime gave descriptions about two suspects who
were in hurry. The first suspect was described as being short and heavy (height
<165 cm and weight >90 kg) and the second suspect was described as being tall
and thin (height >190 cm and weight <60 kg). Write a c-program to input height
and weight of known criminal-pairs in the area and to printout it is suspect or
not.
a)Read above problem. Now read a no. N from user. Then read heights and
widths of N criminal-pairs and print whether they are criminals or not.

7. The cost of operating an electrical device is determined by the formula –


a)C = WTK/1000
Where, W = no. of watts
T = Time in hours
K = cost (in Rs.) per Kilowatt hours
It is required to print a table showing the cost for various values of W from 100
watts to 1000 watts, increment with 50 watts. T from 1 hour to 10 hours, steps of
1 hour. K from Rs. 1.50 to Rs. 10.00 steps of 50 paise.
a. So, now write a menu based program that
b. shows menu with menu-items : Watts, Time and Unit-Cost and
then
c. accepts choice form user
d. and prints table as per choice entered by the user.

8 Write a do-while loop to evaluate and print the values of the quadratic
polynomial
y=x2+10x-11 for the value of x = 0.0 to 1.0 with steps 0.2.

9 Write a for loop to print the numbers between –1 and –30 and their squares
and cubes.

10 Read n numbers from user and find maximum and minimum of those
numbers.

11 Read numbers from user till he wants; also calculate sum of sum of positive
numbers and product of negative numbers.

12 Find the sum of first and last digit of an integer number.

13 1! + 2! + 3! + …+n!

14 X – X3/3! + x5/5!-x7/7!+…

15 Generate a menu-driven calculator that will accept two numbers from the
user and ask for the choice to add, subtract, multiply, divide or exit. After the
result is calculated and displayed as per the user’s choice; the program should
ask the user whether he wants to continue calculations or not.

16 Generate the series:- 1,-3,5,-7,9,-11,13…(1st N numbers).

17 Generate a menu-driven Temperature-conversion program. The menu should


display three options: (1) Fahrenheit-to-Celsius (2) Celsius-to-Fahrenheit (3) Exit.
The program should accept user’s choice and then should function
appropriately. This process function till user does not exit.
18 Write programs to --
Print A, B, C… Z

19 WAP to print z,y,x ………a.


Print z, y, x… a
.
20 Accept one character from user. Check whether it is vowel (i.e. a,e,i,o,u) or
not. Give proper output message as “the character you pressed is vowel” or “the
character you pressed is NOT vowel”. Repeat this process till user wants to
continue.

21 Accept one character from user. Also accept a choice (‘v’ for vowel and ‘c’ for
non-vowel i.e. consonants) from user. The character entered by user should be
tested that is it vowel(‘v’) or non-vowel (‘c’) depending upon choice entered by
user; give proper output message. Repeat this process till user wants to continue.

You might also like