Вы находитесь на странице: 1из 4

INTERNATIONAL UNIVERSITY

SCHOOL OF INDUSTRIAL ENGINERRING

INTRODUCTION TO PROGRAMING C++

LAB 1 and Lab 2:

C++ Programming
Data Types, Making Decisions and
Looping
(Check Sheet)

Student: ..................................................................
Student ID: ..................................................................
Class: ..................................................................
Date: ..................................................................

Page 1 of 4
INTERNATIONAL UNIVERSITY
SCHOOL OF INDUSTRIAL ENGINERRING

II. Lab Exercises with guideline: (please code yourself and show the
output to instructor)
1. Exercises 1: Write a C program to find the sum of individual digits of a positive
integer.
Result:
Enter any integer: 1234
Sum of individual digits is: 10
Lab Instruction signature:
2. Exercises 2: A Fibonacci sequence is defined as follows: the first and second terms
in the sequence are 0 and 1. Subsequent terms are found by adding the preceding two
terms in the sequence. Write a C program to generate the first n terms of the sequence.
Result:
Enter no of items: 5
The Fibonacci sequence is
01123
Lab Instruction signature:
3. Exercises 3: Write a C program to generate all the prime numbers between 1 and n,
where n is a value supplied by the user.
Result:
Enter the limit: 4
The prime numbers are:
2357
Lab Instruction signature:
4. Exercises 4: Write a C program to calculate the following Sum:
Sum = 1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10!
Result:
Enter x value: 2
Sum is: 0
Lab Instruction signature:
5. Exercises 5: Write a C program, which takes two integer operands and one operator
form the user, performs the operation and then prints the result. (Consider the operators
+,-,*, /, % and use Switch Statement)
Result:
1.enter two operands:2 3
enter an operator: +
sum of two numbers 2 3 is: 5
2.enter two operands:3 4
enter an operator: -
subtraction of two numbers 3 4 is: -1
3.enter two operands:3 5

Page 2 of 4
INTERNATIONAL UNIVERSITY
SCHOOL OF INDUSTRIAL ENGINERRING
enter an operator:*
product of two numbers 3 5 is: 15
Lab Instruction signature:
Exercises 6:

Write a C program that reads 10 integers. The program should count the number of positive and
negative values among 10 inputs. Print them on the screen.
Output:
Enter number 1: 16 Enter number 2: -7
Enter number 3: 23 Enter number 4: 49
Enter number 5: -21 Enter number 6: -15
Enter number 7: -33 Enter number 8: 54
Enter number 9: 42 Enter number 10: -37
Number of positive: 5
Number of negative: 5
Lab Instruction signature:

Exercises 7:

Write a C program that reads a student grade which is a character. The program should print the
classification based on the grade as:

Grade Classification
A Excellent
B Good
C Fair
D Average
F Weak
Other characters Invalid

At the end, the program should ask the user to continue to read another grade or not. If yes,
continues, otherwise, prints “Exit program...”.
Output: Enter a grade: B
Good!
Do you want to continue? y
Enter a grade: Y
Invalid.
Enter a grade: D
Average!
Do you want to continue? n
Exit program...
Lab Instruction signature:

Exercises 8:

Write a C program to display first 5 natural number with the first number is entered ,show
number is even or odd then calculate their sum.

Page 3 of 4
INTERNATIONAL UNIVERSITY
SCHOOL OF INDUSTRIAL ENGINERRING
Output: Enter the first number: 5
Number 1 is: 5 (odd)
Number 2 is: 6 (even)
Number 3 is: 7 (odd)
Number 4 is: 8 (even)
Number 5 is: 9 (odd)
Sum = 35
Lab Instruction signature:

Page 4 of 4

Вам также может понравиться