OPERATORS
1. Length and breadth of a rectangle are 5 and 7 respectively. Write a
program to calculate the area and perimeter of the
2. Write a program to input the value of the radius of a circle from
keyboard and then calculate its perimeter and area.
3. Write a program to enter a 4 digit number from keyboard. Add 8 to the
number and then divide it by 3. Now, the modulus of that number is taken
with 5 and then multiply the resultant value by 5. Display the final result.
4. Now, solve the above question using assignment operators (eg. +=, -=,
*=).
5. Enter two numbers from keyboard. Write a program to check if the two
numbers are equal.
6. Write a program to enter the values of two variables 'a' and 'b' from
keyboard and then check if both the conditions 'a < 50' and 'a < b' are true.
7. Now solve the above question to check if atleast one of the conditions 'a
< 50' and 'a < b' is true.
8. If the marks of Robert in three subjects are 78,45 and 62 respectively
(each out of 100 ), write a program to calculate his total marks and
percentage marks.
9. Write a program to enter the values of two variables from the keyboard
and then interchange the values of the two variables. E.g.-
If entered value of x is 5 and y is 10 then
printf("%d %d",x,y )
should print 10 5.
10. Take input of some length in meter and covert it to feet and inches.
11. Write a program to convert Fahrenheit into Celsius.
12. The total number of students in a class are 45 out of which 25 are boys.
If 80% of the total students secured grade 'A' out of which 16 are boys,
then write a program to calculate the total number of girls getting grade
'A'.
IF ELSE
1. Take values of length and breadth of a rectangle from user and check if it
is square or not.
2. Take two int values from user and print greatest among them.
3. A shop will give discount of 10% if the cost of purchased quantity is more
than 1000.
Ask user for quantity
Suppose, one unit will cost 100.
Judge and print total cost for user.
4. A company decided to give bonus of 5% to employee if his/her year of
service is more than 5 years.
Ask user for their salary and year of service and print the net bonus
amount.
5. A school has following rules for grading system:
a. Below 25 - F
b. 25 to 45 - E
c. 45 to 50 - D
d. 50 to 60 - C
e. 60 to 80 - B
f. Above 80 - A
Ask user to enter marks and print the corresponding grade.
6. Take input of age of 3 people by user and determine oldest and youngest
among them.
7. Write a C program to print absolute value of a number entered by user.
E.g.-
INPUT: 1 OUTPUT: 1
INPUT: -1 OUTPUT: 1
8. If
x=2
y=5
z=0
then find values of the following expressions:
a. x == 2
b. x != 5
c. x != 5 && y >= 5
d. z != 0 || x == 2
e. !(y < 10)
9. A student will not be allowed to sit in exam if his/her attendence is less
than 75%.
Take following input from user
Number of classes held
Number of classes attended.
And print
percentage of class attended
Is student is allowed to sit in exam or not.
10. Modify the above question to allow student to sit if he/she has medical
cause. Ask user if he/she has medical cause or not ( 'Y' or 'N' ) and print
accordingly.
SWITCH CASE
1. Write a C program to print day of week name using switch case.
2. Write a C program print total number of days in a month using switch
case.
3.Write a C program to check whether an alphabet is vowel or consonant
using switch case.
4. Write a C program to find maximum between two numbers using switch
case.
5.Write a C program to check whether a number is even or odd using
switch case.
6.Write a C program to check whether a number is positive, negative or
zero using switch case.
7.Write a C program to create Simple Calculator using switch case.
WHOLE LOOP
1.Write a C program to print all natural numbers from 1 to n. - using while
loop
2.Write a C program to print all natural numbers in reverse (from n to 1). -
using while loop
3.Write a C program to print all alphabets from a to z. - using while loop
4.Write a C program to print all even numbers between 1 to 100. - using
while loop
5.Write a C program to print all odd number between 1 to 100.
6.Write a C program to find sum of all natural numbers between 1 to n.
7.Write a C program to find sum of all even numbers between 1 to n.
8.Write a C program to find sum of all odd numbers between 1 to n.
9.Write a C program to print multiplication table of any number.
10.Write a C program to count number of digits in a number.
11.Write a C program to find first and last digit of a number.
12.Write a C program to find sum of first and last digit of a number.
13.Write a C program to swap first and last digits of a number.
14.Write a C program to calculate sum of digits of a number.
15.Write a C program to calculate product of digits of a number.
16.Write a C program to check whether a number is palindrome or not
17.Write a C program to enter a number and print it in words.
18.Write a C program to print all ASCII character with their values.
19.Write a C program to find power of a number using for loop.
20.Write a C program to find all factors of a number.
21.Write a C program to check whether a number is Prime number or not.
22.Write a C program to print all Prime numbers between 1 to n.
23.Write a C program to find sum of all prime numbers between 1 to n.
24.Write a C program to print Fibonacci series up to m
ARRAY
1.Take 10 integer inputs from user and store them in an
array and print them on screen.
2.Take 10 integer inputs from user and store them in an
array. Again ask user to give a number. Now, tell user
whether that number is present in array or not.
3.Take 20 integer inputs from user and print the following:
number of positive numbers number of negative numbers
number of odd numbers number of even numbers
number of 0.
4.Take 10 integer inputs from user and store them in an
array. Now, copy all the elements in another array but in
reverse order.
5.Write a program to find the sum of all elements of an
array.
6.Write a program to find the product of all elements of an
array.
7.Take an array of 10 integers and print all its elements
using pointer.
8.Initialize and print all elements of a 2D array.
9.Find largest and smallest elements of an array.
10.Write a program to print sum, average of all numbers,
smallest and largest element of an array.
11.Write a program to check if elements of an array are
same or not if read from front or back. E.g.-
23151532
12.Take an array of 10 elements. Split it into middle and
store the elements in two different arrays. E.g.-
INITIAL array :58241315639881178
After spliting :58241315639881178
POINTERS
1. Write a program to print the value of the address of the pointer to a
variable whose value is input from user.
2. Write a program to print a number which is entered from keyboard using
pointer.
3. Write a program to print the address of a variable whose value is input
from user.
4. Write a program to print the address of the pointer to a variable whose
value is input from user.
5. Write a program which will take pointer and display the number on
screen. Take number from user and print it on screen using that function.
6. Write a program to find out the greatest and the smallest among three
numbers using pointers.
FUNCTIONS
1.Print multiplication table of 12 using recursion.
2.Write a function to calculate area and perimeter of a rectangle.
3.Write a function to calculate area and circumference of a circle.
4.Write a function to calculate power of a number raised to other. E.g.- abj.
5.Write a function to tell user if he/she is able to vote or not.
( Consider minimum age of voting to be 18. )
6.Write a function to calculate power of a number raised to other ( ab )
using recursion.
7.Write a function “perfect()” that determines if parameter number is a
perfect number. Use this function in a program that determines and prints
all the perfect numbers between 1 and 1000.
[An integer number is said to be “perfect number” if its factors, including
1(but not the number itself), sum to the number. E.g., 6 is a perfect number
because 6=1+2+3].
8.Write a function to check if a number is even or not.
9.Write a function to check if a number is prime or not.
10.Write a function to find factorial of a number but also store the
factorials calculated in a dictionary as done in the Fibonacci series example.
STRING
1.Write a program to print a string entered by user.
2.Write a program to print every character of a string entered by user in a
new line using loop.
3.Write a program to input and display the sentence I love candies.
4.Write a program to find the length of the string "refrigerator".
5.Write a program to enter a string s1 and copy it to another string s2.
6.Write a program to compare if the two strings entered by user are equal
or not without using predefined String functions.
7.Write a program to check if the letter 'e' is present in the word
'Umbrella'.
8.Write a program to check if the word 'orange' is present in the "This is
orange juice".
9.Write a program to find the first and the last occurence of the letter 'o'
and character ',' in "Hello, World".
10.Write the string after the first occurrence of ',' and the string after the
last occurrence of ',' in the string "Hello, Good, Morning".
STRUCTURE
1.Write a program to store and print the roll no., name , age and marks of a
student using structures.
2.Write a program to store the roll no. (starting from 1), name and age of 5
students and then print the details of the student with roll no. 2.
3.Write a program to store and print the roll no., name, age, address and
marks of 15 students using structure.
4.Write a program to add two distances in inch-feet using structure. The
values of the distances is to be taken from the user.
5.Enter the marks of 5 students in Chemistry, Mathematics and Physics
(each out of 100) using a structure named Marks having elements roll no.,
name, chem_marks, maths_marks and phy_marks and then display the
percentage of each student.
6.Write a program to add, subtract and multiply two complex numbers
using structures to function.
7.Write a structure to store the roll no., name, age (between 11 to 14) and
address of students (more than 10). Store the information of the students.
1 - Write a function to print the names of all the students having age 14.
2 - Write a structure to store the roll no., name, age (between 11 to 14) and
address of students (more than 10). Store the information of the students 2
Write another function to print the names of all the students having even
roll no.
3 - Write a structure to store the roll no., name, age (between 11 to 14) and
address of students (more than 10). Store the information of the students 3
Write another function to display the details of the student whose roll no is
given (i.e. roll no. entered by the user).
8.Write a structure to store the name, account number and balance of
customers (more than 10) and store their information.
1 - Write a function to print the names of all the customers having balance
less than $200.
2 - Write a structure to store the name, account number and balance of
customers (more than 10) and store their information 2
Write a function to add $100 in the balance of all the customers having
more than $1000 in their balance and then print the incremented value of
their balance.
9.Write a program to compare two dates entered by user. Make a structure
named Date to store the elements day, month and year to store the dates.
If the dates are equal, display "Dates are equal" otherwise display "Dates
are not equal".
CLASSES OBJ CONSTRUCTOR AND DESTRUCTOR
1. Write a program to print the area of a rectangle by creating a class
named 'Area' having two methods. First method named as 'setDim' takes
length and breadth of rectangle as parameters and the second method
named as 'getArea' returns the area of the rectangle. Length and breadth
of rectangle are entered through keyboard.
2.Create a class named Student with String variable 'name' and integer
variable 'roll_no'. Assign the value of roll_no as '2' and that of name as
"John" by creating an object of the class Student.
3.Assign and print the roll number, phone number and address of two
students having names "Sam" and "John" respectively by creating two
objects of class 'Student'.
4.Write a program to print the area and perimeter of a triangle having sides
of 3, 4 and 5 units by creating a class named 'Triangle' without any
parameter in its constructor.
5.Write a program to print the area and perimeter of a triangle having sides
of 3, 4 and 5 units by creating a class named 'Triangle' with constructor
having the three sides as its parameters.
Write a program to print the area and perimeter of a triangle having sides
of 3, 4 and 5 units by creating a class named Triangle with constructor
having the three sides as its parameters.
Or 222
6.Write a program to print the area of two rectangles having sides (4,5) and
(5,8) respectively by creating a class named 'Rectangle' with a method
named 'Area' which returns the area and length and breadth passed as
parameters to its constructor.
7.Write a program to print the area of a rectangle by creating a class
named Area taking the values of its length and breadth as parameters of its
constructor and having a method named returnArea which returns the area
of the rectangle. Length and breadth of rectangle are entered through
keyboard.
8.Print the average of three numbers entered by user by creating a class
named Average having a method to calculate and print the average.
9.Print the sum, difference and product of two complex numbers by
creating a class named Complex with separate methods for each operation
whose real and imaginary parts are entered by user.
10.Write a program that would print the information (name, year of
joining, salary, address) of three employees by creating a class named
'Employee'. The output should be as follows:
Name Year of joining Address
Robert 1994 64C- WallsStreat
Sam 2000 68D- WallsStreat
John 1999 26B- WallsStreat
11.Add two distances in inch-feet by creating a class named AddDistance.
INHERITANCE
1.Create a class with a method that prints This is parent class and its
subclass with another method that prints This is child class. Now, create an
object for each of the class and call
1 - method of parent class by object of parent class
2 - method of child class by object of child class
3 - method of parent class by object of child class
2.In the above example, declare the method of the parent class as private
and then repeat the first two operations (You will get error in the third).
3.Create a class named Member having the following members:
Data members
1 – Name 2 – Age 3 - Phone number
4 – Address 5 - Salary
It also has a method named 'printSalary' which prints the salary of the
members.
Two classes 'Employee' and 'Manager' inherits the 'Member' class. The
'Employee' and 'Manager' classes have data members 'specialization' and
'department' respectively. Now, assign name, age, phone number, address
and salary to an employee and a manager by making an object of both of
these classes and print the same.
4.Create a class named 'Rectangle' with two data members 'length' and
'breadth' and two methods to print the area and perimeter of the rectangle
respectively. Its constructor having parameters for length and breadth is
used to initialize length and breadth of the rectangle. Let class 'Square'
inherit the 'Rectangle' class with its constructor having a parameter for its
side (suppose s) calling the constructor of its parent class as 'super(s,s)'.
Print the area and perimeter of a rectangle and a square.
ABSTACTION
1.Create an abstract class Parent with a method message. It has two
subclasses each having a method with the same name 'message' that prints
"This is first subclass" and "This is second subclass" respectively. Call the
methods 'message' by creating an object for each subclass.
2.Create an abstract class Bank with an abstract method getBalance. $100,
$150 and $200 are deposited in banks A, B and C respectively. 'BankA',
'BankB' and 'BankC' are subclasses of class 'Bank', each having a method
named 'getBalance'. Call this method by creating an object of each of the
three classes.
3.We have to calculate the percentage of marks obtained in three subjects
(each out of 100) by student A and in four subjects (each out of 100) by
student B. Create an abstract class 'Marks' with an abstract method
'getPercentage'. It is inherited by two other classes 'A' and 'B' each having a
method with the same name which returns the percentage of the students.
The constructor of student A takes the marks in three subjects as its
parameters and the marks in four subjects as its parameters for student B.
Create an object for eac of the two classes and print the percentage of
marks for both the students.
4.An abstract class has a construtor which prints "This is constructor of
abstract class", an abstract method named 'a_method' and a non-abstract
method which prints "This is a normal method of abstract class". A class
'SubClass' inherits the abstract class and has a method named 'a_method'
which prints "This is abstract method". Now create an object of 'SubClass'
and call the abstract method and the non-abstract method. (Analyse the
result)
5.Create an abstract class 'Animals' with two abstract methods 'cats' and
'dogs'. Now create a class 'Cats' with a method 'cats' which prints "Cats
meow" and a class 'Dogs' with a method 'dogs' which prints "Dogs bark",
both inheriting the class 'Animals'. Now create an object for each of the
subclasses and call their respective methods.
6.We have to calculate the area of a rectangle, a square and a circle. Create
an abstract class 'Shape' with three abstract methods namely
'RectangleArea' taking two parameters, 'SquareArea' and 'CircleArea' taking
one parameter each. The parameters of 'RectangleArea' are its length and
breadth, that of 'SquareArea' is its side and that of 'CircleArea' is its radius.
Now create another class 'Area' containing all the three methods
'RectangleArea', 'SquareArea' and 'CircleArea' for printing the area of
rectangle, square and circle respectively. Create an object of class 'Area'
and call all the three methods.
7.Repeat the above question for 4 rectangles, 4 squares and 5 circles.
Hint- Use array of objects.