Lab Manual Isra Noor
Lab Manual Isra Noor
Laboratory Manual
Department of Technology
LAB No. 1
Introduction to C programming Software (DEV C , C FREE)
Introduction to dev c++:
Step #01:
o Open the app Dev c++
Step#02:
Then I created a new project.
Step #03:
Then I named the project.
Step #04:
Then I saved the project.
Step#05:
Then I created a new file.
Step#06:
Then I wrote a code to print “HELLO WORLD” on the output screen.
Step#07:
Then i saved the file in the respected folder.
Step#08:
Compiled the program using f11 key.
Lab review questions:
Question no 1:
Write down the syntax for declaration of variable.
Answer:
<datatype> <variable_name>;
e.g.
Int myNumber;
Float myfloat;
Char mychar;
Question no 2:
How to debug a problem in dev c++?
Answer:
To debug any problem in devc++ follow the following steps.
1. Create (Ctrl+N) or open (Ctrl+O) a project.
2. At Project >> Project Options >> Compiler, select a compiler set that supports debugging (-g3).
3. Click Debug (F5) to compile and debug the project.
4. Place a breakpoint by clicking on a line number or use F4 to pause your program and inspect it.
Question no #03:
Can we use other function libraries in C-Free?
Answer:
Yes, programmers can create their own library functions by packaging them in
header files. So in this way they can use other function libraries.
Question no#04:
What are the reasons for witting programs in C
Answer:
C++ is used due to following reasons:
• C is extendable
• It is easy to understand
• Prescence of many libraries
• Easy to understand
• Low cost
• Fast execution speed
• Portable
• Easy debugging
• Dynamic memory allocation
QUESTION NO#05:
Write a program to add and multiply any three variables a,b,c and print the
result on the output screen.
ANSWER:
Lab no 02
C programming structure, operators, data types, constant and
variables
LAB Exercise Questions
Example 2.1:
Write a program to input length and width in any two variable.
Example 2.2:
Write a program to assign two variables by assignment statement.
Interchange the values and print the result on the screen.
Example 2.3
Write a program to print a message on screen by using “endl” manipulator.
Example 2.4
Write a program in C++ to get two numbers from keyboard during program
execution. Calculate the sum and product of the numbers and then print the
result on the computer.
LAB REVIEW QUESTIONS
Question No1
Write a program in C to print out your name on the output screen
Question No 2
Write the program in C to print the area of circle on the output screen
Question No 3
Write a program in C to add any three numbers and print the result on
output screen.
Question No 4
Write a program in C to get three numbers from user and perform addition
and multiplication.
Question No 5
Write a program in C to assign numeric value to variable year and calculate
the months
LAB No. 03
If statement and If else statement
LAB Exercise Programs
Example 3.1
Write a program to assign value in any variable and check whether it is less
than 20 or not
Example 3.2
Write a program to assign value in to variable ‘a’ and check whether it is
less than 20 or not using if else statement
Example 3.3
Write a program to read three integer numbers then find and print the
largest one among these numbers.
Example 3.4
Write a program that determines a student’s grade. The program will read
three types of scores (quiz, mid-term, and final scores) and determine the
grade based on the following rules: if the average score =90% =>grade=A if
the average score >= 70% and <90% => grade=B if the average score>=50%
and <70% =>grade=C if the average score<50% =>grade=F
Example 3.5
Write a program that prompts the user for the current year, the user's
current age, and another year. It then calculates the age that the user was or
will be in the second year entered
Example 3.6
Write a program to executes a single statement if the given condition is true
Example 3.7
Write a program to calculate the electricity bill. The rates of electricity per
unit are as follow If the units consumed are equal or less than 300, then the
cost is Rs 3/ per unit If units consumed are more than 300, then the cost is
Rs. 3.5/- per unit and a surcharge of 5% of bill is added.
Program 2
Write a program to add two floating point values and display the sum on the
screen
Program 3
Write a program that convert 37 centigrade temperature in to Fahrenheit
using the formula F=9/5 (C +32) and display the temperature in Fahrenheit.
Question 3
Write a program to input any two numbers from user and to perform AND
logical operators
LAB No 5
Nested If-Else Statements
Program:
In this program user is asked to enter the age and based on the input, the if..else
statement checks whether the entered age is greater than or equal to 18. If this
condition meet then display message “You are eligible for voting”, however if the
condition doesn’t meet then display a different message “You are not eligible for
voting”.
LAB No. 06
Switch and Nested Switch Statements
Example 6.1
Write a program to input any number from user and to check number is
divisible by 2 or not (Using switch statement)
LAB Review Questions
Question No 1
Write a program to build a simple calculator using switch Statement.
Question No 2
Write a program to check if entered alphabet is vowel or a consonant.
LAB No. 07
While Loop
Example 7.1
Write a program to print “ I Love Pakistan” five times using the while loop
Example 7.2
Write a program to calculate the sum of first 10 odd numbers . Also print the
odd numbers using while loop
Example 7.3
Write a program to print the multiplication table of a number entered from the
keyboard using while loop
LAB No. 08
Use of For Loop
Example 8.1
Write a program to calculate and print the factorial of a number using for loop
Example 8.2
Write a program to print “I love Pakistan” five times using for loop
Example 8.3
Write a program to input any number from user and print the multiplication
table of given number and print the result on the output screen.
LAB No. 09
Do while Loop
Example 9.1
Write a program to print first ten natural numbers on the output screen using
do while loop.
Example 9.2
Write a program to input and print the record of a student .Repeat this process
for other students until the given condition remains true
Example 9.3
Write a program that calculates the factorial of an integer using the do while
loop statement.
Question 2
Write a program to display the values in between the range 10 to 19 using do
while loop
LAB No. 10
Nested while Loop
Example 10.1
Write a program to print the pattern of number as shown below using
nested while loop
1
12
123
1234
12345
Example 10.3
Write a program to print the pattern of number as shown below using nested
while loop
*
**
***
*****
LAB Review Questions
Question No 1
Write a program to print the multiplication table from 1 to 10 numbers using nested
while loop
LAB No. 11
Nested For Loop
LAB EXERCISE PROGRAMS
Example 11.1
Write a program to print all the composite numbers from 2 to a certain number
entered by user
Example 11.2
Write a program to print the pattern of number as shown below using nested for
loop
*
**
***
****
*****