Code Chum

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

CodeChum

1 A E I O U - We've been doing some research on the contents of text messages sent by users all
around the globe. Our current dilemma is determining how many vowels do users use on average in a
regular text message. If you could find a way to count the number of vowels, we'll take care of finding the
average.

Input Format - A single line containing a string

Sample: Hello World!

Output Format - A single line containing the number of vowels found in the string

Sample: 3

Test Cases:

2 Continuous Input - Write a program that will keep asking the user to input integers until he inputs
-1, or the sum of all inputs have reached or exceeded 2000. When the sum has exceeded 499, print "You're
off to a good start!". When the sum exceeds 999, print "You're halfway through!". Finally, when the sum
exceeds 1499, print "You're almost there!".

If the program ended because of an input of -1, print “Program was terminated. Your total sales are: “.
Else, print “Congratulations! Your total sales are: “

Input Format – Several integer inputs that will either reach a sum of 2000, or ends with a -1.

Sample: 500

200

100

-1

Output Format – Depends

Sample: You’re off to a good start!

You’re off to a good start!

You’re off to a good start!

Program was terminated.

Your total sales are: 800


Test Cases:

3 Debbie Downer – I’m not a positive person. I hate everything that is positive. I feel like spreading
some negativity, and I can do that by adding a bunch of negative numbers! Genius, right? Now come on,
let’s rid the world of its positivity!

Input Format – A single line containing five numbers

Sample: 34 43.5 -53.24 56.3 -10.32

Output Format – A single line containing the sum of all negative numbers rounded off to 2 decimal places.

Sample: -63.56

Test Cases:

4 Everything but Three – I love adding numbers but I absolutely hate the number 3! It’s just the
worst! In order to solidify my hatred for the number 3, I’ve decided to hire you to craft a program capable
of adding every number in the array, except for the number 3.

Input Format – The first line contains the number of elements in the array. The succeeding lines contain
the elements of the array.

Sample: 3

Output Format – A single line that contains the sum of all numbers in the array that are not equal to 3.

Sample: 12

Test Cases:

5 More Often Than One – Hello, I am Detective Raymond from the NBI and we need your assistance.
Hackers have been sending us random numbers and we’re starting to believe that it’s some sort of cryptic
message. The higher-ups believe that it can be decoded by printing the digit that occurs more than once.
They also suggested that if there is more than one, then you would need to print the greater one. If you
could create something that could do that, then you would be doing us a great favor.
Input Format – A single line containing an integer

Sample: 324322

Output Format – A single line that contains the greatest digit that occurred more than once in the integer

Sample: 3

Test Cases:

6 Ascend! – Hey I’ve got this cool idea for an app! It’s kind of simple but just hear me out. All the
user has to do is enter a bunch of integers. Then the application prints the largest sum of a strictly
ascending sequence of the array. A strictly ascending sequence is a sequence where the current number
is always lesser than the next number.

For example, the user enters 2 4 5 1 7 3, the output should be 11. Then that’s it! I think this is going to be
a hit! Don’t you think? Well I do. If you help me then we’re going to be rich!

Note: For this problem, a sequence must contain at least 2 numbers.

Input Format – The first line contains the size of the integer array. The second line contains the integer
array.

Sample: 6

2 4 5 1 7 3

Output Format – A single line containing the largest sum of an ascending sequence of the array

Sample: 11

Test Cases:

7 Odd Pattern – Print the pattern below given the value of n

Input Format – A single line containing an integer n

Sample: 4

Output Format – The pattern of asterisks given the inputted value of n

Sample: *

***
*****

*******

*****

***

Test Cases:

1 Input: 5

Output: *

***

*****

*******

*********

*******

*****

***

8 Count and Say – The count-and-say sequence is a sequence of integers with the first five terms as
follows:

1. 1

2. 11

3. 21

4. 1211

5. 111221

Objective: Generate the n^th term of the count-and-say sequence.

Assume: n >= 1
Input Format – A single line containing an integer.

Sample: 2

Output Format – A single line containing an integer

Sample: 11

Test Cases:

1 Input: 2

Output: 11

2 Input: 3

Output: 21

3 Input: 4

Output: 1211

4 Input: 5

Output: 111221

5 Input: 6

Output: 312211

9 Digits > 3 – Write a C program to input a number from the user and count the number of digits
greater than 3 in the given integer using loop.

Input Format – A single line containing an integer

Sample: 45

Output Format – A single line containing the number of digits greater than 3 of the inputted number

Sample: 2

Test Cases:

1 Input: 45

Output: 2

2 Input: 34
Output: 1

3 Input: 3333

Output: 0

10 Find the GCD – Given 2 integers, a and b, print their Greatest Common Denominator (GCD). The
greatest common divisor of two or more integers is the largest positive integer that divides each of the
integers.

Input Format – A single line containing two integers, a and b

Sample: 9

12

Output Format – A single line containing their GCD

Sample: 3

Test Cases:

11 No pow() of 2 – Write a program that will take as an input an integer n, and will output 2^n without
using the pow() function.

Input Format – A single line containing the value of n

Sample: 5

Output Format – A single line containing the appropriate value

Sample: 32

Test Cases:

1 Input: 5

Output: 32

2 Input: 3

Output: 8
12 Even to 1 – Write a C program that prints each EVEN numbers (only) in decreasing order starting
from 40 to 1.

Output Format – The series of even numbers from 40 to 1, one value each line

Sample: 40

38

36

32

30

28

Test Cases:

13 Product of Digits – Write a C program to input a number from the user and calculate the product
of its digits

Input Format – A single line containing an integer

Sample: 1234

Output Format – A single line containing the product of its digits

Sample: 24

Test Cases:

1 Input: 1234

Output: 24

2 Input: 555

Output: 125
15 Largest Digit of an Integer – Write a program that will output the largest digit of a given integer x

Input Format – A single line containing the value of x

Sample: 194

Output Format – A single line containing the largest digit of the inputted integer

Sample: 9

Test Cases:

1 Input: 194

Output: 9

2 Input: 81

Output: 8

16 Number Pattern 4 – Print the pattern below given the value of n

Input Format – A single line containing the value of n

Sample: 5

Output Format – Multiple lines following a pattern. Take note that the maximum number in the pattern
is 9 and the minimum number is 1

Sample: 98765

87654

76543

65432

54321

Test Cases:

1 Input: 5

Output: 98765

87654

76543
65432

54321

2 Input: 4

Output: 9876

8765

7654

6543

3 Input: 3

Output: 987

876

765

17 1,2,3,…what? – I’m Dr. Frankenstein, and I’ve just created an intelligent monster! It can even
count numbers now but the problem is, it can only count up to 3, so maybe it isn’t so intelligent after all.
I want to use my creation to terrorize the villages but it keeps malfunctioning when it sees a digit that is
greater than 3 so the villagers just put up signs of digits greater than 3. Make a program that is able to
recognize digits greater than 3 so that it can avoid it or I’ll have my monster terrorize YOU instead!

Input Format – A single line containing a single integer

Sample: 45

Output Format – A new line that prints each digit greater than 3 and a single line that contains the word
“none” if there are none.

Sample: 4

Test Cases:

1 Input: 45

Output: 4

5
2 Input: 34

Output: 4

3 Input: 3333

Output: none

18 Often – I’ve decided to gather all of the winning lottery numbers from the past decade or so and
compiled them into long strings of number. All I need now is a way to determine the most frequent
occurring digit in the long number, then maybe I could finally win the lottery! If you help me with this, I
promise to give you 1% of my winnings.

Input Format – A single line that contains an integer

Sample: 3214144

Output Format – A single line that contains the most frequent occurring digit

Sample: 4

Test Cases:

1 Input: 3214144

Output: 4

2 Input: 56245378

Output: 5

19 Digits divisible by 3 – Write a C program to input a number from the user and count the number
of digits divisible by 3 in the given integer using loop.

Input Format – A single line containing an integer

Sample: 49

Output Format – A single line containing the number of digits divisible than 3 of the inputted number or
the word “none” if there isn’t any.

Sample: 1

Test Cases:
1 Input: 49

Output: 1

2 Input: 4

Output: none

3 Input: 3333

Output: 4

20 Number of Even Digits – Write a C program to input a number from the user and count the number
of even digits in the given integer using loop

Input Format – A single line containing an integer

Sample: 12

Output Format – A single line containing the number of even digits of the inputted number

Sample: 1

Test Cases:

1 Input: 12

Output: 1

2 Input: 8

Output: 1

3 Input: 100

Output: 2

Programming Problem

1 order starting from 40 to 1.

Sample:

40 38 36 34 32 30 28 26 24 ... 2
2 (Loops) Write a C program that will print the number series vertically on screen. Use the for-loop
structure

Hint: you may use two variables to generate the number series

Sample:

10 1 9 2 8 3 7 4 6 5

3 Input N integers (Ask from the user how many nos. he/she wants to input).

From the inputted numbers, determine and print the following:

a.) Sum of all nos.

b.) How many even nos. were entered?

c.) How many odd nos. were inputted?

d.) The average of all numbers

At the end, print the sum, average, counted odd numbers, counted even numbers, inputted by the user.

4 Write a program that prints the number from 1 to 20 in a vertical format. Output each of their
squares, cubes, & square roots in a 4 column format (including the nos. from 1-20). Display the square
root of a number in 3 decimal places.

Sample:

NUMBER SQUARE CUBE SQUARE ROOT

1 1 1 1.000

2 4 8 1.414

3 9 27 1.732

. . . .

. . . .

. . . .

20 400 8000 4.472


5 Write a C program that allows a variable to print each number at a time:

Sample:

3692581470

6 Create an application that loops from 1 to 50 and prints out each value on a separate line, except
print out “Fizz” for every divisible by 3, “Buzz” for every divisible by 5, and “FizzBuzz” for every divisible
by 3 and 5. Display number 1-25 in one column and 26-50 on another column.

Sample:

1 26

2 27 Fizz

3 Fizz 28

4 29

5 Buzz 30 FizzBuzz

6 Fizz 31

7 32

8 33

. .

. .

. .

15 FizzBuzz 40

. .

. .

. .

25 50 Buzz
7 Write a program that will ask for an integer input from the user, loop terminates until a value zero
(0) is entered. At the end, display the highest even number entered, If there are no even numbers found
display “no even numbers”.

Note: Use do-while loop only.

Sample:

Input: Input:

4 3

3 5

7 -3

-8 0

10 Output: No even numbers found!

Output: 10

8 Tribonacci Number – Define as: the next term is the sum of the three previous terms.

Objectives: To solve number sequence problem using any loop structure (for-loop, while loop, do-while
loop).

Sample:

Input: 10

Output: 1 1 1 3 5 9 17 31 57 105

9 Generate an (row X col) Addition table. Use a nested-loop.

Objectives: To implement a loop within a loop structure.

Sample:

Input: row = 5 and col = 4

Output:

Addition Table

1 2 3 4
2 4 5 6

3 5 6 7

4 6 7 8

5 7 8 9

10 Write a loop implementation in C that will display all the factors of a number (inputted by the
user). If a number can be expressed as a product of two whole numbers, then the whole numbers are
called factors of that number. “Factors” are the numbers you multiply to get another number. For
instance, the factors of 15 are 3 and 5, because 3 * 5 – 15.

Sample:

The factors of 25 are 1, 5, and 25

The factors of 24 are 1, 2, 4, 6, 8, 12, and 24

The factors of 64 are 1, 2, 4, 8, 16, 32, and 64

The factors of 6 are 1, 2, 3, and 6

11 Write a C loop structure that will produce PARKSIDE’S TRIANGLE – is generated from two
numbers, the size and the seed. The size determines how many rows are in the triangle, and the seed
determines the first number in the triangle.

Note: Size – refers to the no. of rows the Parkside Triangle must contain

Seed – the starting value of the seed [1-9] only

Sample:

Enter size: 6 Enter size: 5

Enter seed: 1 Enter seed: 3

1 3

23 45

456 678

7891 9123
23456 45678

789123

Enter size: 6 Enter size: 5

Enter seed: 1 Enter seed: 9

1 9

23 12

456 345

7891 6789

23456 12345

789123

12 A Kaprekar number is a number whose square when divided into two parts and such that sum of
parts is equal to the original number and none of the parts has value 0.

Sample:

1 Input: 45 (45^2 = 2025 and so, 20 + 25 = 45)

Output: Kaprekar

2 Input: 297 (297^2 = 88209 and so, 88 + 209 = 297)

Output: Kaprekar

3 Input: 13 (13^2 = 169 and so, 1 + 69 = 70)

Output: Not Kaprekar

13 A number is called happy if it leads to 1 after a sequence of steps where in each step number is
replaced by sum of squares of its digit that is if we start with Happy Number and keep replacing it with
digits square sum, we reach 1. Test cases: 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94,
97, 100

For example: 19 is Happy Number,


1^2 + 9^2 = 82

8^2 + 2^2 = 68

6^2 + 8^2 = 100

1^2 + 0^2 + 0^2 = 1

As we reached to 1, 19 is a Happy Number.

Sample:

Input: 20 Input: 7

Output: False Output: True

You might also like