LAB 4 (Loops)
LAB 4 (Loops)
1. Print the maximum value of an unsigned int using One’s Compliment (~) Operator in C.
2. Write a C program that reads an integer n from the keyboard and prints out the factorial of
n.
3. Write a C program that calculates the sum of integers between 9 and 300 inclusive which
are divisible by 7 but not divisible by 63.
Expected output:
Sum of integers between 9 & 300 that are divisible by 7 but not by 63 is 5684
Expected output:
11 22 33 44 55 66 77 88 99
Expected output:
6. Write a C program to enter numbers until the user wants. At the end, display the total
number of positive, negative and zeros entered.
Expected output:
Enter a number : 6
Another number(Y/N)? Y
Enter a number: -3
Another number(Y/N)? Y
Enter a number: 0
Another number(Y/N)?Y
Enter a number: 9
Another number(Y/N)? N
Number of positive numbers: 2
Number of negative numbers: 1
Number of zeroes: 1
7. Write a C program that accepts a positive integer n less than 50 from the terminal and
prints out the sum 14 + 24 + 44 + 74 + 114 +···+m4, where m is less than or equal to n. If the
input is outside the range, the program terminates with appropriate message.
8. Write a C program that asks the user to enter a positive integer n less than 10. If the user
enters an invalid input, the code repeats the command of asking the user for a positive
integer less than 10 until the input is correct. It then prints out the sum of the first n terms of
the series 14 + 24 + 44 + 74 + 114 +···.
9. Write a C program that accepts a positive integer n and a real number x from the keyboard
and prints out the sum of the n terms of the series
10. Write a C program that accepts a non-negative integer from the keyboard and checks
whether the entered number is a palindrome number.
Test data and expected output:
Enter a non-negative integer:9
9 is a palindrome number
Enter a non-negative integer:246642
246642 is a palindrome number
Enter a non-negative integer:24312
24312 is NOT a palindrome number