0% found this document useful (0 votes)
17 views2 pages

C 2425 Lab02

The document outlines a programming lab focused on C/C++ with ten distinct tasks. These tasks include writing programs for inputting integers, calculating factorials, computing taxi fares, identifying days of the week, checking for consonants or vowels, verifying Armstrong numbers, determining prime numbers, checking leap years, processing n-digit numbers, and summing digits until a single digit is achieved. Each task includes specific requirements and example inputs and outputs.

Uploaded by

Lý Khải Minh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

C 2425 Lab02

The document outlines a programming lab focused on C/C++ with ten distinct tasks. These tasks include writing programs for inputting integers, calculating factorials, computing taxi fares, identifying days of the week, checking for consonants or vowels, verifying Armstrong numbers, determining prime numbers, checking leap years, processing n-digit numbers, and summing digits until a single digit is achieved. Each task includes specific requirements and example inputs and outputs.

Uploaded by

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

Programming C/C++ Lab

Lab 02

1. Write a program to input integers, the program ends when user input 0. Print the minimum
(different from 0) and maximum number (different from 0) among the input numbers.
Instead of printing just the min and max, also print the number of times they appear in
the input.:

Input: -3 5 -2 9 8 10 5 -1 0 10
Min: -3 (1 time)
Max: 10 (2 times)

2. Write a function to calculate the factorial with given integer n, which satisfies the
following:
if n is odd, F= 1 ∗ 3 ∗ 5 ∗ … ∗ 𝑛
if n is even, F= 2 ∗ 4 ∗ 6 ∗ … ∗ 𝑛

3. Write a Taxi meter program to calculate the taxi fare for a given travel distance.

a. The 1st 2km is 15,000 VND


b. The next 250m will cost 2000 VND
c. If the travel distance is larger than 30km then each extra km will cost only
5000VND
Allow user to input the travel distance in km and print the amount of money to be paid.
Moreover, allow the user to input multiple trips and display the total fare.

4. Write a program to input an integer within range 1..7 then print out the corresponding day
of the week. Example: 3 Tuesday

5. Write a program to find wether a character is sonsoneant or vowel (a, e, i, o, u are vowels)

6. Write a function to check if the given number is Amstrong or not (sum of cubes of
individual digits is equal to the number itself)

7. Write a program to check whether a given number is Prime or not. After that, allow the
user to input N numbers and display only the prime ones.
Enter numbers (separated by space): 12 17 19 20 23
Prime numbers: 17, 19, 23

8. Write a program to check whether an given year is leap year or not (leap year when it is
divisable by for and divisible by 100 or 400). Then extend the problem that allow the user
to input a range of years and print all leap years in that range.
Enter start year: 2000
Enter end year: 2024
Leap years: 2000, 2004, 2008, 2012, 2016, 2020, 2024

9. Write a program that inputs an n-digit number then output its n digits from least to most
significant and print the sum of digits:

Input: 132768
Output: 8 6 7 2 3 1
Sum of digits: 27

10. Sum of Digits Until Single Digit.


Write a program that repeatedly adds the digits of an integer until the result is a single-digit
number.
Example:
Input: 9875
Output: 2
Explanation: 9 + 8 + 7 + 5 = 29 → 2 + 9 = 11 → 1 + 1 = 2

Input: 12345
Output: 6
Explanation: 1 + 2 + 3 + 4 + 5 = 15 → 1 + 5 = 6

You might also like