Programming Lab Problems

ME 2222 (Sessional on ME-2221)
Programming Language (C)
Department of Mechanical Engineering
Khulna University of Engineering & Technology (KUET)
Lab 01: Introduction to C: Basic programming
1. Write a simple C program to get “I LOVE ALLAH” on the output.
2. Write a C program to add, subtract, multiply and divide two variables x & y.
3. Solve x^2-5y+3 and get the value of x in the output for given values of y.
Assignments:
1. Write a program to read 100 values and give their average.
2. Write a C program to calculate the volume of a Cylinder and Cube .
3. Find the summation of the series 1+3+5+……….+n
Lab 02: If-else: Basic
1. Given 10 values of X, find the mean of the values, which do not exceed 35.
2. Program to check the number is odd or even.
3. Write a C program to compute remainder & quotient of two variables.
Assignments:
1. Given 10 values of X, find the mean of the values, which lie between 27 and 53
both inclusive.
2. Write a C program for solving a quadratic equation ax^2+bX+C=0 and find the
roots of x.
Engr.Rubiat Mustak,Lecturer,Dept.of ME
Page 1
Lab 03: If-else application
1. Write a C program to generate the electricity bill according to their
consumption.
Consumption
unit(KWh)
0~200
Rate per unit at BDT
201~400
Extra 100 tk plus 3.5
tk per unit excess of
200
401~600
Extra 250 tk plus 4.5
tk per unit excess of
400
601~above
Extra 450 tk plus 5.75
tk per unit excess of
600
2.5 per unit
Assignments:
1. Write a program to receive the CT(out of 20), attendance(Out of 10) & final
exam(out of 70) marks of a student and gives the obtained grade of the student
according to:
Engr.Rubiat Mustak,Lecturer,Dept.of ME
Page 2
Lab 04: For Loop: Introduction
1. Find the summation of natural numbers using for loop. (as:
1+2+3+4+………+n; 1+3+5+7+9……….+n; ).
2. Find the factorial of any number (n!) .
3. Find the sum of all integers divisible by 5 from 1 to 1000.
4. Write a C program to calculate the sum of the series:
(x/n!)+(x^2/n!)+(x^3/n!)+………….+(x^r/n!) where x, r, n all are variables
Assignments:
1. Find the sum all integers divisible by 3 from 1 to 1000.
2. Find the sum of inverse of 1000 natural numbers.
3. Find the sum of the series: 1 + 1 + 2 + 3 + 5 + 8 + 13 + ... 20 terms.
Lab 05: Nested For loops:
1. Given 10 different numbers and sort them in an ascending order.
Assignments:
1. Given 10 different numbers and sort them in a descending order.
Lab 06: While loop/do while loop
1. Using while loop write a program to calculate the sum of natural numbers.
2. Write the Source Code to Find Factorial of a Number using while loop.
3. Find the average of 10 numbers using do while loop.
Assignments:
1. Write the Source Code to Find Factorial of a Number using do while loop.
2. Find the average of 10 numbers using do while loop.
3. Using do while loop write a program to calculate the sum of natural numbers.
Engr.Rubiat Mustak,Lecturer,Dept.of ME
Page 3
Lab 07: Function:
1. Write a C program to calculate sum of two variables using function .
2. Find the sum of factorials of 25 natural numbers.
Assignments:
1. Write a C program to calculate sum of four variables using function .
2. Find the sum of factorials of 50 natural numbers using function.
3. Create a function to compute the area of a circle and use the function to find the
areas of 15 circles with radii given.
Lab 08: Recursion
1. Source Code to Calculate Factorial Using Recursion.
Assignments:
1. Source code to calculate factorial of 10 numbers using recursion.
Lab 09: Array
1. Show 10 elements of array and give the average .
2. Print elements of a matrix
3. Program to subtract elements of two matrix .
Assignments:
1. Write a C program to find addition of all elements of an Array.
2. Program to multiply all elements of two matrix.
3. Program to find transpose of a matrix
Lab 10: Pointer:
1. Add two number using pointers.
Assignment:
1. Add three number using pointers.
Engr.Rubiat Mustak,Lecturer,Dept.of ME
Page 4
Lab 11: Structure & Union
1. C Program to Store Information of Single Variable .
2. Source code to add two distance using structure.
Assignments:
1. Source Code to Store Information of 10 students Using Structure.
Lab 12: String
1.Write a C program to reverse a string.
2. From a list of 1000 names, five characters each, find how many are
‘ABDUL’.
Assignment:
1. Input name and age of each of 20 different persons and sort the data in order of
descending age.
Lab 13: Files(Opening and Closing)
1. File operations .
2. Introduction to MATLAB.
Engr.Rubiat Mustak,Lecturer,Dept.of ME
Page 5