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

Lab-3 Task

Uploaded by

mianabdullah6747
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Lab-3 Task

Uploaded by

mianabdullah6747
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Programming Fundamentals

Lab – 3
1. Write a function called "minimum" that takes two integers as parameters and returns
the smaller of the two numbers. Then, write a main function that prompts the user to
input two numbers and calls the "minimum" function to find and print the smaller
number.
2. Write a function called "grade" that takes a student's percentage as a parameter and
returns the letter grade corresponding to that percentage (e.g. 90-100 is an A, 80-89 is
a B, etc.). Then, write a main function that prompts the user to input a percentage and
calls the "grade" function to find and print the corresponding letter grade.

3. Write a program that prompts the user to input a number and then uses a switch
statement to print whether the number is positive, negative, or zero.
4. Write a function to find first and last digit of any number using while loop.
5. Write a function that takes two integers as input and returns the larger of the two.
6. Write a program that prompts the user for their age and then displays whether they
are a teenager or an adult. Use a function to determine the user's age group.
7. Write a program that prompts the user for a year, and then uses a function to
determine whether the year is a leap year or not. A leap year is a year that is evenly
divisible by 4, but not by 100 unless it is also divisible by 400.
8. Write a function that takes in a string and a character as input and returns the
number of times the character appears in the string. Use the function in a program
that prompts the user for a string and a character and then displays the number of
times the character appears in the string.
9. Write a program that takes in a string and uses a function to check if the string is a
palindrome (a word, phrase, or sequence that reads the same backwards as forwards)
or not.
10. Write a program that prompts the user for a sentence and then uses a function to
remove all the spaces from it, and then reverse the sentence.
11. Write a program that prompts the user for a number and then determines whether
the number is a prime number. Use a function to determine whether the number is a
prime number. A prime number is a number that is divisible by only 1 and itself.
12. Write a program that prompts the user for a sentence and then reverses the order of
the words in the sentence. Use a function to reverse the order of the words in the
sentence.
13. Write a program that prompts the user for a sentence and then counts the number of
occurrences of each letter in the sentence. Use a function to count the number of
occurrences of each letter in the sentence.
14. Write a function that takes 5 integers and returns the mode (the most frequently
occurring element).
15. Write a program that prompts the user for a number and then prints out the
Fibonacci sequence up to that number. Use a function to generate the Fibonacci
sequence.
16. Print ASCII values and their equivalent characters. ASCII value vary from 0 to 255.
17. Write a C++ program to calculate factorial of a number. Factorial of any number n is
represented by n! and is equal to 1*2*3*....*(n-1)*n. E.g.-
a. 4! = 1*2*3*4 = 24
b. 3! = 3*2*1 = 6
c. 2! = 2*1 = 2
d. Also,
e. 1! = 1
f. 0! = 0
18. Write a menu for all above task and ask user what action wants to perform then
execute that function.

You might also like