4 - Looping Statements
4 - Looping Statements
PROGRAMMING IN C LABORATORY
4 : C Programs using I/O statements, conditional and looping statements
===========================================================
Learning Outcome :
To be proficient in basic features of C
- using I/O statements (getchar/putchar, scanf/printf)
- operators and expressions (arithmetic / unary / conditional / relational / logical )
- conditional constructs ( if / nested if, switch)
- looping constructs (for, while, do-while)
To learn to develop code incrementally
Write the algorithm to solve the following problems and implement them in C.
Example
Enter a number ? 4
*-*-*-*
*-*-*
*-*
*
*-*
*-*-*
*-*-*-*
7) Write a program that computes sum of N integers (Version 1)
a. Get input for N, multiple times until -999 is given (Version 2) (Use do-
while)
b. Get input for N, multiple times until ‘STOP’ is given (Version 3)
c. Validate N to be a positive number less than 100. (Version 4)
d. Print error message for invalid input and exit (Version 5) (Use break)
e. If input is invalid, print message and ask for another input. (Version 6)
8) Design a calculator to perform the operations namely addition, subtraction, multiplication,
division and square of a number. (Hint: Provide operation options for the user to choose,
after getting two numbers of type float) (Use case)
9) Write a C program to check if a number has three consecutive 5s. If yes, print YES, else
print NO.
Example
Number: 1353554
Result: NO
Number: 345559
Result: YES
10) Implement the solution for (1) without a condition.
*******************