C Pratice Programs

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Beginner

1. Create a program which generates fibonacci series till a number 'n' where 'n' is entered by the user. For eg. if the user enters 10 then the
output would be: 1 1 2 3 5 8.

2. Write a program to simulate a simple calculator. It should accept two numbers from the user along with the required operation to be
performed. Addition, Subtraction, Division and Multiplication are the basic operations that should be implemented. Feel free to
implement the other operations.

3. Write a program which finds the factorial of a number entered by the user. (check for all conditions)

4. Develop a program to convert currency X to currency Y and visa versa.

5. Determine how many of the characters are vowels and how many are consonants in a given line of text. Also terminate the string
when the input character encountered is other than the alphabets.

6. Perform 4-letter WORD UNSCRAMBLING i.e. List all possible combinations of 4-letters in a word. Ex: The word 'TEST' can be
unscrambled as TEST, TETS, TSET, TSTE, TTSE, TTES, etc.

7. Determine how much money is in a piggy bank that contains several 50 paise coins, 25 paise coins, 20 paise coins, 10 paise coins and 5
paise coins. Use the following values to test your program : Five 50 paise coins, Three 25 paise coins, Two 20 paise coins, One 10 paise
coin and Fifteen 5 paise coins.

8. Write a program which reverses the numerals in an integer, that is 326 becomes 623, etc.

9. Write a program that prompts the user for the area of a circle and calculates the radius of that circle and prints it out.

10. Write a program that does temperature conversion from either Fahrenheit to Celsius, or the other way around. Your program should
first prompt the user for which type of conversion they want to do. Then your program should prompt the user for the temperature
they want to convert. Finally, your program should output the proper converted temperature. Incidentally, the formula for conversion
from celsius to fahrenheit is  F = 1.8*C + 32
Intermediate

1. Create a simple Palindrome checker program. The program should allow the user to enter a string and check whether the given string
is a palindrome or not. Only digits and alphabets should be considered while checking for palindromes -- any other characters are to
be ignored.

2. W.A.P. in C to REVERSE THE WORDS IN A GIVEN LINE OF TEXT. [HINT : USE Built-in function 'strtok' in 'string.h' header file]

3. W.A.P. in C to READ a line of text and WRITE it out BACKWARDS using RECURSIVE Function.
4. Write a program that takes as input two positive integers, the height and length of a parallelogram and prints a parallelogram of that
size with stars to the screen. For example, if the height were 3 and the length were 6, the following would be printed:

******

******

******

5. Write a function that takes in six integer parameters: x1, y1, r1, x2, y2 and r2, where (x1,y1) is the center of a circle with radius r1 and (x2,
y2) is the center of a circle with radius r2. Your program should return the number of intersection points between the two circles.
(Hint: This number will always be 0, 1 or 2.)

6. Write a program that asks the user for the price of gasoline per gallon, the number of gallons of gas currently in their car, the miles per
gallon their car gets, and the length of their road trip in miles and calculates and prints out the amount the user will have to spend on
extra gas to complete the road trip. (You may assume that the user will have to buy some gas to complete the trip.)

7. Write a program that asks the user for how many slices are in a whole pizza and how many people are eating the pizza. Since we must
be perfectly fair, all people must get exactly the same number of slices. Any leftover slices (which must be less than the number of
people) will be given to the family dog. Your program should output how many slices everyone eats and how many slices the dog gets.

8. W.A.P. in C to perform 4-letter WORD UNSCRAMBLING i.e. List all possible combinations of 4-letters in a word. Ex: The word
'TEST' can be unscrambled as TEST,TETS,TSET,TSTE,TTSE,TTES,etc.
Expert

1. W.A.P which performs Addition, Subtraction and Multiplication of matrices. The dimensions of both the matrices would be specified
by the user.

2. W.A.P in C to SWAP the contents of 3 variables without using the temporary (or extra) variables.

3. W.A.P. in C to find the Fifth root of the sum of the squares of the first 100 ODD numbers only.

4. W.A.P. in C to multiply any two numbers without using * (asterisk) [Hint : Use BITWISE OPERATORS]

5. W.A.P. in C to check whether given number x is equal to the value 2 POWER i or something. [Hint: where i>=0 using BITWISE
operators ONLY.]

6. W.A.P. in C that acts as a guessing game in which the user has eight tries to guess a randomly generated number within 100. The
program will tell the user each time whether he guessed high or low. The user WINS the game when the number guessed is same as
randomly generated number.

7. W.A.P. to determine how much money is in a piggy bank that contains several 50 paise coins, 25 paise coins, 20 paise coins, 10 paise
coins and 5 paise coins. Use the following values to test your program : Five 50 paise coins, Three 25 paise coins, Two 20 paise coins,
One 10 paise coin and Fifteen 5 paise coins. (Answer : Rs. 4.50)

8. W.A.P. in C to determine how many of the characters are vowels and how many are consonants in a given line of text. Also terminate
the string when the input character encountered is other than the alphabets(a-z or A-Z) and Blank spaces.
[Hint:(a) When the input string is 'C FOR SWIMMERS, TEST YOUR C PROGRAMMING STRENGTHS'. Consider the string 'C FOR
SWIMMERS' only Because ',' is encountered. (b) When the input string is 'Y2K PROBLEM'. Consider the character 'Y' only Because
the '2' is encountered.]

9. Write a program to play a game of marbles. The game starts with 32 marbles and two players. Each player must take 1, 2 or 3 marbles
on their turn. Turns go back and forth between the two players. The winner is the person who takes the last marble. Your program
should prompt each player with a message that states the current number of marbles and asks them how many they'd like to take.
Continue until there is a winner. Then your program should print out the winner (either player #1 or player #2.) (Incidentally, if both
players play optimally, who always wins? What is their strategy?)

10. Write a function that takes in the coefficients a (not 0), b, and c (all doubles) to a quadratic equation and returns the smaller of the two
roots (a double) as the result. You may assume that the roots of the quadratic are real. The formula for the roots of a quadratic is given
below:

− b ± b 2 − 4ac
x=
2a

You might also like