CS 111 Lab 4
CS 111 Lab 4
1. Login to default directory and see if the directory LAB4 exists. If the directory LAB4 exists,
then remove it. Now create the directory LAB4 and go to the directory LAB4. Create all
the programs in the directory LAB4
2. 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
3. Write a C program that accepts an integer from keyboard and calculates the sum of digits of
an integer.
Test data and expected output:
4. 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.
Test data and expected output:
5. 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 + · · ·.
Test data and expected output:
7. Write a C program that reads an integer n from the keyboard and prints out the factorial of n.
Test data and expected output:
Enter an integer:6
Factorial of 6 is 720
Enter an integer:-3
n must be non-negative
8. 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
∞
x2n+1
tn = (−1)n
X
sin(x) = tn ,
n=0 (2n + 1)!
9. Write a C program that reads a real number x from the keyboard and calculates the sum of
the series ∞
x2n+1
tn = (−1)n
X
sin(x) = tn ,
n=0 (2n + 1)!
by adding terms as long as |tn | > 10−6 .
Test data and expected output:
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
11. Write a C program that accepts a non-negative integer from the keyboard and checks whether
the entered number is a Armstrong number. (An n-digit number that is the sum of the n-th
powers of its digits is called an Armstrong number)
Test data and expected output:
12. A perfect number is a positive number in which sum of all positive divisors excluding that
number is equal to that number. Write a C program that accepts a positive integer from the
keyboard and checks whether the entered number is a perfect number.
Test data and expected output:
13. Write a C program that prints out the prime numbers between 1 and 100. The output should
be such that each row contains a maximum of 7 prime numbers.
Expected output: