0% found this document useful (0 votes)
79 views

PPS Assignment - 4: Test Case

The document contains 7 programming problems: 1) Calculate the sum of integers between 9-300 divisible by 7 but not 63. 2) Accept an integer and calculate the sum of its digits. 3) Accept a positive integer n<50 and print the sum of series 14+24+...+m4 where m<=n. 4) Accept a positive integer n<10, print series sum, repeat on invalid input. 5) Accept integers until 0 or negative, output count, max, min, average of positives. 6) Accept an integer n, print factorial of n. 7) Accept positive integer, check if it is a perfect number.

Uploaded by

msugnan9124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

PPS Assignment - 4: Test Case

The document contains 7 programming problems: 1) Calculate the sum of integers between 9-300 divisible by 7 but not 63. 2) Accept an integer and calculate the sum of its digits. 3) Accept a positive integer n<50 and print the sum of series 14+24+...+m4 where m<=n. 4) Accept a positive integer n<10, print series sum, repeat on invalid input. 5) Accept integers until 0 or negative, output count, max, min, average of positives. 6) Accept an integer n, print factorial of n. 7) Accept positive integer, check if it is a perfect number.

Uploaded by

msugnan9124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PPS Assignment - 4

1. 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.
Test Case:

Sum of integers between 9 & 300 that are divisible by 7 but not by 63 is 5684

2. Write a C program that accepts an integer from keyboard and calculates the sum of digits
of an integer.
Test Case:

Enter an integer: 3456


Sum of the digits of 3456 is 18

Enter an integer: -23


Sum of the digits of -23 is 5

3. 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 Case:

Enter a +ve integer less than 50: 0


Invalid input

Enter a +ve integer less than 50: 39


Sum of the series is 2898549
Enter a +ve integer less than 50: 0
Invalid input

4. 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 Case:

Enter a +ve integer less than 10: 0


Invalid input,
enter again: 4 is 2674
Sum of the 4 terms of the series
Enter a +ve integer less than 10: 4
is 2674
Sum of the 4 terms of the series
Enter a +ve integer less than 10: 11
Invalid input, is 17315
enter again: 5
Sum of the 5 terms of the series
5. Write a C program that accepts integers from the keyboard until we enter a zero or a
negative number. The program will output the number of positive values entered, the
minimum value, the maximum value and the average of all numbers.
Test Case:

Enter a +ve integer: 6


Enter next +ve integer: 3
Enter next +ve integer: 2
Enter next +ve integer: - 4

Number of +ve values entered Is: 3


Maximum value entered is :6
Minimum value entered is:2
Average value is 3:6667

Enter a +ve integer:0


No positive number entered

6. Write a C program that reads an integer n from the keyboard and prints out the factorial of
n.
Test Case:

Enter an integer:6
Factorial of 6 is 720

Enter an integer:-3
n must be non-negative
7. 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 Case:

Enter a positive integer: -2


Input must be positive

Enter a positive integer: 8128


8128 is a perfect number

Enter a positive integer:28


28 is a perfect number

Enter a positive integer:64


64 is NOT a perfect number

You might also like