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

C PROGRAMMING MANUAL

STUDENT MANUAL

MAY 16, 2018


DEKUT
NYERI
Table of Contents
1 Week 1-Writing Algorithms. ...................................................................................... 3
2 Week 2-Using variables and Operators. ...................................................................... 7
3 Week 3-Using Control Statements. ........................................................................... 19
INTRODUCTION

1 Week 1-Writing Algorithms.


Programming algorithm as a recipe that describes the exact steps needed for the computer to
solve a problem or reach a goal. We've all seen food recipes - they list the ingredients needed
and a set of steps for how to make the described meal.
Well, an algorithm is just like that. In computer lingo, the word for a recipe is a procedure,
and the ingredients are called inputs. Your computer looks at your procedure, follows it to
the letter, and you get to see the results, which are called outputs.
A programming algorithm describes how to do something, and your computer will do it
exactly that way every time. Well, it will once you convert your algorithm into a language it
understands!
Example
Write an algorithm to compute the area of a rectangle
Start
Input length, width
Compute area(area=length*width)
Print results
End
Exercise
1. Write an algorithm to add three numbers and give the sum
2. Write an algorithm to find the sum of two numbers.
3. Write an algorithm to find the sum of three numbers.
4. Write an algorithm to find the area of square.
5. Write an algorithm to find the area of triangle.
6. Write an algorithm to find the perimeter of rectangle
7. Write an algorithm to find the perimeter of square
8. Write an algorithm to find the area of circle
9. Write an algorithm to find the circumference of circle
10. Write an algorithm to find the area of parallelogram
11. Write an algorithm to find the area of rhombus
12. Write an algorithm to find the area of trapezium
13. Write an algorithm to find the greater of two numbers.
14. Write an algorithm to find the smaller of two numbers.
Week 1-Drawing Flowcharts.
A flowchart provides a pictorial representation of the algorithm using the symbols
shown below.

Example
1. Flowchart c program to find area of circle
2. C program to check input year is leap year or not

Exercise
Draw a flowchart to determine
1. Area of square
2. Volume of cuboid
3. Volume of sphere
4. Volume of cylinder
5. maximum of two number
6. Citizen is eligible for voting or not
7. Student is lean or fat
8. Number is positive or negative
9. Student is pass or fail
2 Week 2-Using Printf Statements.
1. Write a program that prints the numbers 1 to 4 on the same line using one printf
statement.
2. Write a program that prints the following shapes with asterisks

3. Display the following checkerboard pattern with eight printf statements and then display
the same pattern with one printf statements
3 Week 2-Using Variables & Operators.
1. Write a program that asks the user to enter two numbers, obtains them from the user
and prints their sum, product, difference, quotient and remainder.
2. Write a program that reads in the radius of a circle and prints the circle’s diameter,
circumference and area. Use the constant value 3.14159 for π. Perform each of these
calculations inside the printf statement(s) and use the conversion specifier %f.
3. Write a program that calculates the squares and cubes of the numbers from 0 to 10 and
uses tabs to print the following table of values

4. Create an application that calculates your daily driving cost, so that you can estimate
how much money could be saved by car -pooling, which also has other advantages such
as reducing carbon emissions and reducing traffic congestion. The application should
input the following information and display the user’s cost per day of driving to work:
a) Total KMs driven per day.
b) Cost per gallon of gasoline.
c) Average KMs per gallon.
d) Parking fees per day.
e) Toll cost per day.
5. Create a BMI calculator application that reads the user’s weight in kilograms and height
in meters), then calculates and displays the user’s body mass index. Use the formulae

The application should display the following information based on the users BMI
6. Write a C program that convert a temperature from Centigrade to Fahrenheit. Use
C = (5/9) * (F - 32)
Expected Output :
Input a temperature (in Centigrade): 45
113.000000 degrees Fahrenheit.

Output

7. Write a C program that calculates the volume of a sphere.


Expected Output :
Input the radius of the sphere : 2.56
The volume of sphere is 70.276237
Output

8. Write a C program that prints the perimeter of a rectangle to take its height and width
as input.
Expected Output:
Input the radius of the sphere: 2.56
The volume of sphere is 70.276237.
Output

9. Write a C program that converts kilometers per hour to miles per hour.
Expected Output :
Input kilometers per hour: 15
9.320568 miles per hour
Output

10. Write a C program that takes hours and minutes as input, and calculates the total
number of minutes.
Expected Output :
Input hours: 5
Input minutes: 37
Total: 337 minutes
Output

11. Write a program in C that takes minutes as input, and display the total number of hours
and minutes.
Expected Output :
Input minutes: 546
9 Hours, 6 Minutes
Output

12. Write a program in C to calculate the sum of three numbers with getting input in one
line separated by a comma.
Expected Output :
Input three numbers separated by comma : 5,10,15
The sum of three numbers : 30
Output
13. Write a C program to perform addition, subtraction, multiplication and division of two
numbers.
Expected Output :
Input any two numbers separated by comma : 10,5
The sum of the given numbers : 15
The difference of the given numbers : 5
The product of the given numbers : 50
The quotient of the given numbers : 2.000000

Output
14. Write a C program to find the third angle of a triangle if two angles are given. Expected
Output :
Input two angles of triangle separated by comma: 50,70
Third angle of the triangle: 60

Output
15. Write a program in C that reads a forename, surname and year of birth and display the
names and the year one after another sequentially. Go to the editor
Expected Output :
Input your firstname: Tom
Input your lastname: Davis
Input your year of birth: 1982
Tom Davis 1982

Output
4 Week 3-Using Control Statements.

1. Write a C program to accept two integers and check whether they are equal or not
Test Data : 5,6
Expected Output :
Number1 and Number2 are equal

Output

2. Write a C program to check whether a given number is even or odd


Output
Test Data: 15
Expected Output:
15 is an odd integer

Solution

3. Write a C program to check whether a given number is positive or negative


Output

4. Write a C program to find whether a given year is a leap year or not. Go to the editor
Test Data : 2016
Expected Output :
2016 is a leap year.
Code
Output

5. Write a C program to read the age of a candidate and determine whether it is eligible for
casting his/her own vote.
Test Data : 21
Expected Output :
Congratulation! You are eligible for casting your vote
Code
Output

6. Write a C program to read the value of an integer m and display the value of n is 1 when
m is larger than 0, 0 when m is 0 and -1 when m is less than 0.
Test Data : -5
Expected Output :
The value of n = -1
Code
Output
7. Write a C program to accept the height of a person in centimeter and categorize the
person according to their height as shown

Test Data : 135


Expected Output :
The person is Dwarf
Code
Output

8. Write a C program to find the largest of three numbers.


Test Data : 0,-5,-2
Expected Output :
Number 0 is the greatest among three

Output
9. Write a C program to find the eligibility of admission for a technology/engineering
course based on the following criteria:
Marks in Maths >=65
Marks in Phy >=55
Marks in Chem>=50
Total in all three subject >=180
or
Total in Math and Physics >=140
Code
Output
Output

10. Write a program that asks the user to enter two integers, obtains the numbers from the
user, then prints the larger number followed by the words “is larger.” If the numbers are
equal, print the message “These numbers are equal.”
11. Write a program that inputs three different integers from the keyboard, then prints the
sum, the average, the product, the smallest and the largest of these numbers. Use only
the single-selection form of the if statement you learned in this chapter.
12. Write a program that reads an integer and determines and prints whether it’s odd or
even.
5 Week 4-Using Loop Statements.
1. Write a program in C to display the first 10 natural numbers.
Expected Output :
1 2 3 4 5 6 7 8 9 10
Code

Solution

2. Write a C program to find the sum of first 10 natural numbers.


Expected Output :
The first 10 natural number is :
1 2 3 4 5 6 7 8 9 10
The Sum is : 55
Solution
3. Write a program in C to read 10 numbers from keyboard and find their sum and average.
Code

Output
4. Write a program in C to display the cube of the number upto given an integer. Test Data:
Input number of terms : 5
Expected Output :
Number is : 1 and cube of the 1 is :1
Number is : 2 and cube of the 2 is :8
Number is : 3 and cube of the 3 is :27
Number is : 4 and cube of the 4 is :64
Number is : 5 and cube of the 5 is :125
Code

Solution

5. Write a program in C to display the multiplication table of a given integer.


Test Data :
Input the number (Table to be calculated) : 15
Expected Output :
15 X 1 = 15
...
...
15 X 10 = 150
Code

Solution

You might also like