RAJSHAHI UNIVERSITY OF
ENGINEERING AND TECHNOLOGY
Assignment of CSE
Submitted by: Submitted to:
Biplob Kumar Ghosh Shoyoda Shafika Moni
Roll: 142095 Lecturer,
Sec:B Department of CSE,
Department: Mechanical Engineering RUET
LAB:1
Practice 1:
Write a program to display the following output:
My name is xx
I have come from yy
I am a student of zz
#include <stdio.h>
int main()
printf("My name is Biplob kumar Ghosh.\n I have come from Sirajgonj. \n I am a
student of Mechanical Engineering department.");
return 0;
Write a program to display the following output using the above concept.
**
***
****
#include <stdio.h>
int main()
printf("*\n**\n***\n****");
return 0;
Practice 2:
Write a program that can read an integers from keyboard and display it.
#include <stdio.h>
int main()
{int n;
printf("waiting for an integer\n");
scanf("%d",&n);
printf("The value is: %d\n",n);
return 0;
Write a program that can read an integer number from keyboard and display it.
#include <stdio.h>
int main()
{float n;
printf("waiting for a float number\n");
scanf("%f",&n);
printf("The value is: %.2f\n",n);
return 0;
Practice 3:
Write a program for calculating the area of acircle.
#include <stdio.h>
int main()
{float radius,area;
printf("Enter a radious of a circle\n");
scanf("%f",&radius);
area=3.1416*radius*radius;
printf("\nArea of the circle:%.2f\n",area);
return 0;
Calculate the area of a rectangle through C code using the above concept.
#include <stdio.h>
int main()
{float a,b,area;
printf("Enter the length and width\n");
scanf("%f%f",&a,&b);
area=a*b;
printf("\nArea of the rectangle:%.2f\n",area);
return 0;
Practice 4:
Write a program that takes two real numbers as input from keyboard, adds them and
display the result.
#include <stdio.h>
int main()
{ int a,b,c;
scanf("%d%d",&a,&b);
c=a+b;
printf("The result is:%d\n",c);
return 0;
Exercise:
Suppose, I=10 amp, R=4 ohm. Write a code using C language to calculate the voltage
value by taking user input from keyboard.
#include <stdio.h>
int main()
{ int v,i,r;
scanf("%d%d",&i,&r);
v=i*r;
printf("The result is:%d\n",v);
return 0;
Take four integer values as inputs from keyboard, calculate their average and display the
result.
#include <stdio.h>
int main()
{int a, b, c, d,temp;
float avg;
scanf("%d%d%d%d",&a,&b,&c,&d);
temp=a+b+c+d;
avg=temp/4;
printf("Avarage:%f",avg);
return 0;
LAB:2
Practice 1
Write your first C program to demonstrate the working of arithmetic operators in C.
#include <stdio.h>
int main()
{int a=9, b=4, c;
c=a+b;
printf("a+b=%d\n",c);
c=a-b;
printf("a-b=%d\n",c);
c=a*b;
printf("a*b=%d\n",c);
c=a/b;
printf("a/b=%d\n",c);
return 0;
Write a program to convert a given number of days into months and days.
#include <stdio.h>
int main()
{int days;
scanf("%d",&days);
printf("%d Months and %d Days",days/30,days%30);
return 0;
Practice:02
Write a program to find size of integers , float , double and character of your system.
#include <stdio.h>
int main()
int a;
float b;
double c;
char d;
printf("The size of integer, a is : %d bytes\n", sizeof(a));
printf("The size of float, b is : %d bytes\n", sizeof(b));
printf("The size of double value, c is : %d bytes\n", sizeof(c));
printf("The size of character,d is : %d bytes\n", sizeof(d));
return 0;
Practice:03
Write a program to display number of days in February using conditional operator.
#include <stdio.h>
int main()
{
int feb, days;
printf("Enter 1 if the year is leap year otherwise enter 0 \n");
scanf("%d", &feb);
days = (feb =='0')?28:29;
printf("The Number of days of February : %d", days);
return 0;}
Write a program to check whether a year is leap year or not.
#include <stdio.h>
int main()
int year;
printf("Enter a year\n");
scanf("%d",&year);
if(year%4==0){
printf("%d is leap year",year);
}
else printf("%d is not leap year",year);
return 0;
Practice:04
Write a program to solve a quadratic equation.
#include <stdio.h>
#include <math.h>
int main()
double a, b, c, x, Value 1 , Value 2;
printf("Waiting for the values of a, b, c : \n");
scanf("%lf%lf%lf", &a&b&c);
x = sqrt(b*b-4*a*c);
Value 1 = (-b+x)/2a;
Value 2 = (-b-x/2a);
printf("Value 1 = %0.4lf Value 2 = %0.4lf", Value 1, Value 2);
return 0;
}
Write aprogram to calculate the square of a value by using the function power and also
by using shorthand operator.
#include <stdio.h>
#include <math.h>
int main()
{
double a, b, c, x, Value 1 , Value 2;
printf("Waiting for the values of a, b, c : \n");
scanf("%lf%lf%lf", &a&b&c);
x = sqrt(b*b-4*a*c);
Value 1 = (-b+x)/2a;
Value 2 = (-b-x/2a);
printf("Value 1 = %0.4lf Value 2 = %0.4lf", Value 1, Value 2);
return 0;
Practice:05
Write a program to enter two number from keyboard and swap the value of these two
by using shorthand operator.
#include <stdio.h>
int main ()
float A, B, temp;
printf("Enter the value of A = ");
scanf("%f", &A);
printf("Enter the value of B = ");
scanf("%f", &B);
temp= A;
A = B;
B = temp;
printf("After swapping, value of A is :%0.0f\n", A);
printf("After swapping, value of B is : %0.0f\n", B);
return 0;
}
Practice:06
Write a C program to check weaher a character is alphabet or not.
#include<stdio.h>
int main()
system("COLOR F2");
char c;
int result;
printf("Enter an Alphabet : ");
scanf("%c", &c);
result = ((c>='a'&&c<='z') || (c>='A'&&c<='Z'))?1:0;
printf("The Entered Charactered is %d", result);
return 0;
Write a program to check whether a number entered by an user is even or odd.
#include<stdio.h.
Int main() {
Int a,result;
Printf(“enter the number:”);
Scanf(“%d”,&a);
Result=(a%2==0)?even:odd;
Printf(“then entered number is=%d”,result);
Return o;
}
Output:
Enter the number: 4
The entered number is= even.
LAB:3
Practice 1
Write your first C program to print the number entered by user only if the number
entered is negative.
#include <stdio.h>
int main()
{int num;
printf("Enter a number to check\n");
scanf("%d",&num);
if(num<0){
printf("Number=%d\n",num);
return 0;}
Write a C program to check whether a number entered by user is even or odd.
#include <stdio.h>
int main()
{int num;
printf("Enter a number to check\n");
scanf("%d",&num);
if(num%2==0){
printf("The number is even\n",num);
else
printf("The number is odd");
return 0;
}
Practice 2
Write a C program to relate two integers entered by user using=or>or<sign
#include <stdio.h>
int main()
int a, b;
printf("Enter a number to check relation between two numbers :\n ");
scanf("%d%d",&a, &b);
if(a==b)
printf("Result : a=b", a, b);
else if(a>b)
printf("Result : a>b", a, b);
else if(a<b)
printf("Result : a<b", a, b);
return 0;
Write a C program to do the grading of students on the basis of average marks.
Average Marks Grade
80-100 Honors
60-79 First Division
50-59 Second Division
40-49 Third Division
0-39 Fail
#include <stdio.h>
int main()
{int marks;
printf("Enter a number to check\n");
scanf("%d",&marks);
if(marks>79){
printf("Honors\n",marks);
if else(marks<80&&marks>59){
printf("First Division\n");
if else(marks<60&&marks>49){
printf("Second Division\n");
}
if else(marks<50&&marks>39){
printf("First Division\n");
else
printf("Fail")
return 0;}
Practice 3
Write a C program to add two numbers without using addition operator.
#include<stdio.h>
int main()
int a,b;
int sum;
printf (“Enter any two integers:”);
scanf(“%d%D”,&a,&b);
sum=a-~b-1;
printf(“Sum of two integers:%d”,sum);
return 0;
Write a C program to add two numbers without using subtraction operator.
#include<stdio.h>
int main()
int a,b;
int sum;
printf (“Enter any two integers:”);
scanf(“%d%D”,&a,&b);
sum=a+~b-1;
printf(“Subtraction of two integers:%d”,sum);
return 0;
Practice 4
Write a C program to creat a simple calculator for addition , subtraction, multiplication
and division using switch…..case statement in C programming.
#include<stdio.h>
Int main(){
Char o;
Float num1,num2;
Printf(“enter operator either + or – or * or /”);
Scanf(“%c”,& o);
Printf(“enter two operands”);
Scanf(“%f%f”,&num1,&num2);
Switch (o){
Case ‘+’:
Printf(“%.1f+%.1f=%.1f”,num1,num2,num1+num2);
Break;
Case ‘-’:
Printf(“%.1f-%.1f=%.1f”,num1,num2,num1-num2);
Break;
Case’*’:
printf(“%.1f*%.1f=%.1f”,num1,num2,num1*num2);
Break;
Case ‘/’:
Printf(“%.1f/%.1f=%.1f”,num1,num2,num1/num2);
Break;
Default:
Printf(“error! Operator is not correct”);
Return 0;
Write a C program to do the grading fo student on the basis of average marks using
switch…case statement in C programing.
#include <stdio.h>
int main()
{int marks;
printf("Enter a number to check\n");
scanf("%d",&marks);
switch(marks/10){
case 10:
case 9:
case 8:
printf("A+");
break;
case 7:
printf("A");
break;
case 6:
printf("A-");
break;
case 5:
printf("B");
case 4:
printf("C");
break;
default:
printf("Fail")
break;}
return 0;
An electric power distribution company charges its domestic consumers as follow:
Consumption Units Rate of Charge
0-200 Rs. 0.50 per unit
201-400 Rs. 100 plus Rs.0.65 per unit excess of 200
401-600 Rs. 230 plus 0.80 per unit excess 400
601 and above Rs.390 Rs. 1.00 per unit excess of 600
Write a program to read the customer number and power consumed units and print the
amount to be paid by the customer.
#include <stdio.h>
int main()
{float num, unit;
printf("Enter customer number and units\n");
scanf("%f",&num);
scanf("%f",&unit);
if(unit>=0&&unit<=200){
printf("Customer number %f Amount to be paid:%f",num,unit*0.50);
else if(unit>=201,unit<=400){
printf("Customer number %f Amount to be paid:%f",num,100+unit*0.65);
else if(unit>=401,unit<=600){
printf("Customer number %f Amount to be paid:%f",num,230+unit*0.80);
else
printf("Customer number %f Amount to be paid:%f",num,390+unit*1);
return 0;
LAB:4
Practice:01
Write a program to find the sum of first n natural numbers (1,2,3… are called natural
numbers ) where n is entered by user.
#include <stdio.h>
int main()
int n, count, sum=0;
printf("Enter a Value of n: ");
scanf("%d",&n);
for(count=1; count<=n; count++)
sum = sum + count;
printf("%d", sum);
return 0;
Write a c program to find and display all the factors of a number entered by an user.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,count,factor;
printf("Enter the number: ");
scanf("%d",&n);
for(count=1;count<=n;count++){
printf("%d",count);
}
return 0;
}
Output:
Enter the number: 10
1x2x3x4x5x6x7x8x9x10.
Practice 2
Write a C program to check wheather a number is palindrome or not.
#include <stdio.h>
int main()
int n,reverse=0,rem,temp;
printf("Enter the integer:");
scanf("%d",&n);
temp=n;
while(temp!=0){
rem=temp%10;
reverse=reverse*10+rem;
temp/=10;
}
if(reverse==n)
printf("%d is a palindrome",n);
else
printf("%d is not a palindrome",n);
return 0;
Write a C program to find number of digits in a number.
#include <stdio.h>
int main()
int num,count=0;
printf("Enter a number: ");
scanf("%d",&num);
while(num!=0){
num=num/10;
count++;
printf("Total digits is: %d",count);
return 0;
Practice 3
Write a C program to check whether a number is prime or not.
#include <stdio.h>
int main()
{ int n,i,flag=0;
printf("Enter the number:");
scanf("%d",&n);
for(i=2;i<=n/2;i++){
if( n%i==0){
flag=1;
break;
}
}
if(flag==0){
printf("prime");
else{
printf("not prime");
return 0;
Write a c program to display all prime numbers between two interval entered by user.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n1, n2, i, flag;
printf("Enter two numbers(intevals): ");
scanf("%d %d", &n1, &n2);
printf("Prime numbers between %d and %d are: ", n1, n2);
while (n1 < n2)
{
flag=0;
for(i=2; i<=n1/2; ++i)
{
if(n1%i == 0)
{
flag=1;
break;
}
}
if (flag == 0)
printf("%d ",n1);
++n1;
}
return 0;
}
Practice 4
Write a program to display Fibonacci series up to crrtain number by user.
#include <stdio.h>
int main()
int n=0,m=1,display=0,num;
printf("Enter an integer:");
scanf("%d",&num);
printf("fibonacci series: %d+%d+",n,m);
display=n+m;
while(display<num){
printf("%d+",display);
n=m;
m=display;
display=n+m;
return 0;
Practice:05
Write a C program to find Greatest Common Divisor of two integer value.
#include<stdio.h>
int main()
int a, b, c, i;
printf("Enter Two Integers : ");
scanf("%d%d", &a, &b);
for(i=1;i<=a||i>=b;i++)
if(a%i==0 && b%i==0)
c=i;
printf("HCF is %d and %d is %d", a, b, c);
return 0;
Exercise 1:
Write a c program to find the product of 4 integers entered by a user. If user
enters o skip it.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c,d,mul;
printf("Enetr the number:");
scanf("%d%d%d%d",&a,&b,&c,&d);
while(a!=0,b!=0,c!=0,d!=0){
mul=a*b*c*d;
break;
}
printf("Answer:%d",mul);
return 0;
}
Output;
Enetr the number:4 5 6 8
Answer:960
Exercise 2:
Write a c program that takes an integer number from user and reverse that
number.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,rem,rev=0;
printf("Enter the number:");
scanf("%d",&n);
while(n!=0){
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
printf("reverse number:%d",rev);
return 0;
}
Output:
Enter the number:123
reverse number:321