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

Practice Programming Exercises

The document provides 14 practice programming exercises involving tasks like: 1) Printing a word 1000 times 2) Printing numbers from 1 to n 3) Counting down from n to 0 then printing "Blast Off!" 4) Calculating total price of items 5) Calculating perimeter of a rectangle 6) Calculating sum of numbers from 1 to n 7) Computing n! (factorial of n) 8) Calculating class average grade 9) Printing Fibonacci sequence elements 10) Printing nth Fibonacci number 11) Counting vowels and consonants in a word 12) Summing digits of a number 13) Tracking score of a basketball game over quarters and overtime
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views

Practice Programming Exercises

The document provides 14 practice programming exercises involving tasks like: 1) Printing a word 1000 times 2) Printing numbers from 1 to n 3) Counting down from n to 0 then printing "Blast Off!" 4) Calculating total price of items 5) Calculating perimeter of a rectangle 6) Calculating sum of numbers from 1 to n 7) Computing n! (factorial of n) 8) Calculating class average grade 9) Printing Fibonacci sequence elements 10) Printing nth Fibonacci number 11) Counting vowels and consonants in a word 12) Summing digits of a number 13) Tracking score of a basketball game over quarters and overtime
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

EMPTEC2 Practice Programming Exercises 

Write C language programs to help automate the following tasks.

1. Write a program that prints the word Animo 1,000 times.

2. Write a program that accepts a positive integer n. The program should then output a list of
all whole numbers from 1 to n, each on a separate line.

3. Write a program that accepts a positive integer n, representing the number of seconds before
the rocket will launch. The program should then output the numbers from n going down to 0,
each on a separate line. After the line containing the 0, the program should output another
line with the words Blast Off!.

4. Write a program that asks the price of ten items. The program should display the total price
of all the items.

5. Write a program that asks for the length and width of the rectangle. The program should
display the perimeter of the rectangle. At the end of the program, it should ask if the user
wants to try again. If the user answers Y, then the program should start again from the
beginning.

6. Write a program that accepts a single positive integer 𝑛. The program should output the
value of ∑𝑛𝑖=1 𝑖 . This means that if the input is 5, the program should output the sum of all
numbers from 1 to 5, or 15. If the input is 10, the program should output the sum of all
numbers of 1 to 10, or 55.

7. Write a program that accepts a single non-negative integer 𝑛. The program should compute
for the value of 𝑛! and output it. 𝑛! is defined as the product of all numbers from 1 to n.
However, if 𝑛 = 0, 𝑛! is equivalent to 1.

8. Write a program that asks how many students are there in a class. After that, ask for the
grade of each student. The program should display the average grade of the class.

9. The Fibonacci sequence starts with 1, 1. The next number in the sequence is determined by
adding the two previous numbers before it. Therefore, the Fibonacci sequence is: 1, 1, 2, 3, 5,
8, 13, 21, 34, 55, 89, ...

Write a program that prints the first 100 elements of the Fibonacci sequence.

10. Write a program that asks the user to input a positive integer 𝑛. The program should then
output the 𝑛th element of the Fibonacci sequence. For example, if 𝑛 is 4, the program should
output the 4th element of the Fibonacci sequence which is 3. Refer to Problem 7 for the
definition of the Fibonacci sequence.
11. Write a program that asks the user how many letters are there in a word. Ask for the letters
one at a time. Assume all letters are typed in lower case by the user. The program should
display how many vowels and how many consonants there are.

12. Write a program that accepts any positive integer. The program should output the sum of its
digits. For example, if the input is 520, the output should be 7. If the input is 1975, the
output should be 22.

13. UAAP season has begun. Write a program that asks for the score obtained by the Green
Archers and Blue Eagles in a basketball game for each quarter (there are four quarters in
total in a basketball game). Note that for each quarter the program should ask for the number
of points obtained in that quarter only, not the total score after that quarter.

After four quarters, output the winner. If it’s a tie, the program should say Overtime! and
then ask for the number of points obtained by each team for the overtime round. If there is
already a winner, output the winner. If not, the program should keep on going overtime as
needed until a winner has been decided..

14. Consider the following menu for a fast food chain:

Price
Fried Chicken ₱75.00
Burger Steak ₱40.00
Tapsilog ₱60.00

Write a program that asks for the user’s order. After that, the program should ask: Are you
still hungry? (Y/N). If the user inputs Y, the program should ask for another order. The
program should keep on doing this until the user says that he is not hungry anymore. The
program should then output the total price that the user must pay.

You might also like