Loops – Arithmetic – Problem #12

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: Medium

Problem Statement

Write a C Program that will read in a set of at most 10 positive integers. However, if an integer 0 or less is read somewhere, then that means that no more integers are to be read. Now among the positive integers read, find out if the sum of those which are divisible by either 2 or 3 or 5 is greater than the sum of those which are not divisible by any one of 2 or 3 or 5, or whether the two sums are equal. (Loop CAN be used and will help to write a shorter program, though it is not absolutely necessary to use loops. Arrays are NOT to be used) Save the file as A04_<Roll Number>.c (example A04_21AG10002.c). Build, Run for and test it for the given data. Then upload the .c file for the Assignment. In particular, you will do the following: 1. Read in integers one by one and print them till either you read 10 positive numbers or read a 0 or negative number. (Print only the positive numbers). Create a new line after they are printed. 2. In a new line, Print the sum (Sum1) of numbers divisible by any one of 2 or 3 or 5 as – Sum1 (Divisible) = <Value> 3. In a new line, Print the sum (Sum2) of numbers not divisible by any of 2 or 3 or 5 as – Sum2 (Not Divisible) = <Value> 4. In a new line, Print which sum is larger or whether they are equal. Test Data: (Inputs will be given one after another without commas) a) 2 3 5 7 15 11 7 0 b) 8 12 23 17 19 18 -4 c) 11 23 18 16 29 31 9 12 16 7

Back to Lab Problems
Loops/Arithmetic/Problem #12

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #12

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.