MD Imrajul Alam Computer Science & Engineering C Cse-Ii I 1,2,3,4,5

You might also like

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

Programming for Problem Solving Lab (C)

(ESCS - 291)
CSE – 2nd Sem. – 1st Year

Programming for Problem Solving Lab (C) – ES(CS)291


REPORT ON: …………………………..………………………………………………………………Lab.

MD IMRAJUL ALAM
NAME: …………………………………………………………………………………………………………..

COMPUTER SCIENCE & ENGINEERING


DEPARTMENT: ……………………………………………………………………………………………..

2ND
20/CSE/002 SEM: …….…….…
ROLL NO: .……………..….…… C
GRP: ….…… CSE-II
SECTION: ……..........

I
ASSIGNMENT NO: ………..……PROGRAM NO: …..………………………………………....
1,2,3,4,5

TITLE / OBJECTIVE:

SOLVING PROBLEMS IN C USING CONDITIONAL STATEMENT


.………………………………………………………………………………………..................................

-If-Else
……….………………………………………………………………………………..................................

………….……………………………………………………………………………..................................

………….……………………………………………………………………………..................................

………….……………………………………………………………………………..................................

08/06/2021 SUBMISSION DATE: ………………….......


PERFORMANCE DATE: …....……………….. 15/06/2021

EXAMINER’S SIGNATURE: ……………………………………………………………………………..


Assignment No. – II Page - 1 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM
Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

1. Write a Program in C to find whether a number is EVEN or ODD.

Program: PR01.c

#include <stdio.h>

int main()
{

printf("\t\t****EVEN OR ODD****\t\t\n\n");

int num;
printf("\nEnter the number: ");
scanf("%d", &num);

if(num % 2 == 0)
{
printf("\n%d is a even number.", num);
}

else
{
printf("\n%d is a odd number.", num);
}

return 0;
}

Assignment No. – II Page - 2 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

OUTPUT:

****EVEN OR ODD****

Enter the number: 656

656 is a even number.

Process returned 0 (0x0) execution time : 5.435 s


Press any key to continue.

****EVEN OR ODD****

Enter the number: 479

479 is a odd number.

Process returned 0 (0x0) execution time : 4.931 s


Press any key to continue.

Assignment No. – II Page - 3 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

2. Write a Program in C to find the Largest of Three Numbers.

Program: PR02.c

#include<stdio.h>

int main()
{
printf("\t\t*****FIND THE LARGEST NUMBER*****\n\n");
int a,b,c,big;

printf("\nENTER THE FIRST NUMBER: ");


scanf("%d",&a);

printf("\nENTER THE SECOND NUMBER: ");


scanf("%d",&b);

printf("\nENTER THE THIRD NUMBER: ");


scanf("%d",&c);

big=a;

if(b>big)
{
big=b;
}

if(c>big)
{
big=c;
}

printf("\n\tTHE LARGEST NUMBER IS: %d", big);

return 0;
}

Assignment No. – II Page - 4 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

OUTPUT:

*****FIND THE LARGEST NUMBER*****

ENTER THE FIRST NUMBER: 45

ENTER THE SECOND NUMBER: 42

ENTER THE THIRD NUMBER: 40

THE LARGEST NUMBER IS: 45


Process returned 0 (0x0) execution time : 12.918 s
Press any key to continue.

*****FIND THE LARGEST NUMBER*****

ENTER THE FIRST NUMBER: 55

ENTER THE SECOND NUMBER: 59

ENTER THE THIRD NUMBER: 52

THE LARGEST NUMBER IS: 59


Process returned 0 (0x0) execution time : 12.126 s
Press any key to continue.

*****FIND THE LARGEST NUMBER*****

ENTER THE FIRST NUMBER: 64

ENTER THE SECOND NUMBER: 63

ENTER THE THIRD NUMBER: 69

THE LARGEST NUMBER IS: 69


Process returned 0 (0x0) execution time : 9.137 s
Press any key to continue.

Assignment No. – II Page - 5 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

3. Write a Program in C to enter marks of five subjects. Find the Sum and the Average of them
and then assign grade to the students according to the rule below

AVG GRADE
>=90% to <=100% O
>=80% to <=89% E
>=70% to <=79% A
>=60% to <=69% B
>=50% to <=59% C
>=40% to <=49% D
<40% FAIL

Program: PR03.c

#include <stdio.h>

int main()
{
printf("\t\t****RESULTS****\t\t\n\n");

int physics,chemistry,mathematics,biology,statistics;
int sum;
float average;

printf("Enter marks of physics: ");


scanf("%d", &physics);
if(physics>100)
{
printf("Enter marks which is not more than 100\n");
printf("Enter marks of physics again: ");
scanf("%d", &physics);
}
printf("Enter marks of chemistry: ");
scanf("%d", &chemistry);
if(chemistry>100)
{
printf("Enter marks which is not more than 100\n");
printf("Enter marks of chemistry again: ");
scanf("%d", &chemistry);
}
printf("Enter marks of mathematics: ");
scanf("%d", &mathematics);
if(mathematics>100)
{
printf("Enter marks which is not more than 100\n");
printf("Enter marks of mathematics again: ");
scanf("%d", &mathematics);
Assignment No. – II Page - 6 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM
Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

}
printf("Enter marks of biology: ");
scanf("%d", &biology);
if(biology>100)
{
printf("Enter marks which is not more than 100\n");
printf("Enter marks of biology again: ");
scanf("%d", &biology);
}
printf("Enter marks of statistics: ");
scanf("%d", &statistics);
if(statistics>100)
{
printf("Enter marks which is not more than 100\n");
printf("Enter marks of statistics again: ");
scanf("%d", &statistics);
}

sum = (physics + chemistry + mathematics + biology + statistics);


printf("The sum of the marks is: %d \n", sum);

average = (float)(physics + chemistry + mathematics + biology + statistics)/5;


printf("The average of the marks is: %0.2f \n",average);

if(average >=90 && average<=100)


{
printf("Your Grade is O");
}
else if(average>= 80 && average<=89)
{
printf("Your Grade is E");
}
else if(average>= 70 && average<=79)
{
printf("Your Grade is A");
}
else if(average>= 60 && average<=69)
{
printf("Your Grade is B");
}
else if(average>= 50 && average<=59)
{
printf("Your Grade is C");
}
else if(average>= 40 && average<=49)
{
Assignment No. – II Page - 7 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM
Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

printf("Your Grade is D");


}
else if(average < 40 )
{
printf("You are FAIL!");
}

return 0;
}

Assignment No. – II Page - 8 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

OUTPUT:

****RESULTS****

Enter marks of physics: 115


Enter marks which is not more than 100
Enter marks of physics again: 95
Enter marks of chemistry: 92
Enter marks of mathematics: 99
Enter marks of biology: 94
Enter marks of statistics: 98
The sum of the marks is: 478
The average of the marks is: 95.60
Your Grade is O
Process returned 0 (0x0) execution time : 25.492 s
Press any key to continue.

****RESULTS****

Enter marks of physics: 95


Enter marks of chemistry: 91
Enter marks of mathematics: 99
Enter marks of biology: 96
Enter marks of statistics: 99
The sum of the marks is: 480
The average of the marks is: 96.00
Your Grade is O
Process returned 0 (0x0) execution time : 11.417 s
Press any key to continue.

****RESULTS****

Enter marks of physics: 89


Enter marks of chemistry: 90
Enter marks of mathematics: 95
Enter marks of biology: 81
Enter marks of statistics: 85
The sum of the marks is: 440
The average of the marks is: 88.00
Your Grade is E
Process returned 0 (0x0) execution time : 14.870 s
Press any key to continue.

Assignment No. – II Page - 9 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

****RESULTS****

Enter marks of physics: 84


Enter marks of chemistry: 74
Enter marks of mathematics: 79
Enter marks of biology: 82
Enter marks of statistics: 76
The sum of the marks is: 395
The average of the marks is: 79.00
Your Grade is A
Process returned 0 (0x0) execution time : 15.845 s
Press any key to continue.

****RESULTS****

Enter marks of physics: 80


Enter marks of chemistry: 61
Enter marks of mathematics: 69
Enter marks of biology: 71
Enter marks of statistics: 60
The sum of the marks is: 341
The average of the marks is: 68.20
Your Grade is B
Process returned 0 (0x0) execution time : 14.345 s
Press any key to continue.

****RESULTS****

Enter marks of physics: 74


Enter marks of chemistry: 52
Enter marks of mathematics: 60
Enter marks of biology: 51
Enter marks of statistics: 55
The sum of the marks is: 292
The average of the marks is: 58.40
Your Grade is C
Process returned 0 (0x0) execution time : 20.394 s
Press any key to continue.

****RESULTS****

Enter marks of physics: 54


Enter marks of chemistry: 42
Enter marks of mathematics: 49
Enter marks of biology: 52
Enter marks of statistics: 47
The sum of the marks is: 244

Assignment No. – II Page - 10 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

The average of the marks is: 48.80


Your Grade is D
Process returned 0 (0x0) execution time : 9.883 s
Press any key to continue.

****RESULTS****

Enter marks of physics: 32


Enter marks of chemistry: 39
Enter marks of mathematics: 45
Enter marks of biology: 38
Enter marks of statistics: 36
The sum of the marks is: 190
The average of the marks is: 38.00
You are FAIL!
Process returned 0 (0x0) execution time : 16.497 s
Press any key to continue.

Assignment No. – II Page - 11 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

4. Write a Program in C to check whether a Year is Leap year or not.

Program: PR04.c

#include <stdio.h>

int main()
{
printf("\t\t****LEAP YEAR OR NOT****\t\t\n\n");

int year;
printf("Enter the year: ");
scanf("%d", &year);

if (year % 400 == 0)
{
printf("This is a leap year and it has 366 days.");
}

else if (year % 100 == 0)


{
printf("This is not a leap year and it has 365 days.");
}

else if (year % 4 == 0)
{
printf("This is a leap year and it has 366 days.");
}

else
{
printf("This is a not leap year and it has 365 days.");
}

return 0;
}

Assignment No. – II Page - 12 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

OUTPUT:

****LEAP YEAR OR NOT****

Enter the year: 2000


This is a leap year and it has 366 days.
Process returned 0 (0x0) execution time : 22.073 s
Press any key to continue.

****LEAP YEAR OR NOT****

Enter the year: 3000


This is not a leap year and it has 365 days.
Process returned 0 (0x0) execution time : 13.408 s
Press any key to continue.

****LEAP YEAR OR NOT****

Enter the year: 2016


This is a leap year and it has 366 days.
Process returned 0 (0x0) execution time : 7.343 s
Press any key to continue.

****LEAP YEAR OR NOT****

Enter the year: 2021


This is a not leap year and it has 365 days.
Process returned 0 (0x0) execution time : 6.526 s
Press any key to continue.

Assignment No. – II Page - 13 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

5. Write a Program in C to find the Roots of a Quadratic Equation.

Program: PR05.c

#include <stdio.h>
#include <math.h>

int main()
{

printf("\t\t****ROOTS OF QUADRATIC EQUATION****\t\t\n\n");

double discriminant, root1, root2, realPart, imaginaryPart;

double a, b, c;
printf("Enter the first coefficients a: ");
scanf("%lf", &a);

printf("Enter the second coefficients b: ");


scanf("%lf", &b);

printf("Enter the third coefficients c: ");


scanf("%lf", &c);

discriminant = b * b - 4 * a * c;

if (discriminant > 0)
{
printf("The real and different roots are: \n");
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("root 1 = %.2lf \n",root1);
printf("root 2 = %.2lf \n",root2);
}

else if (discriminant == 0)
{
printf("The real and equal roots are: \n");
root1 = root2 = -b / (2 * a);
printf("root 1 = root 2 = %.2lf", root1);
}

else
{
Assignment No. – II Page - 14 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM
Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

printf("The complex and different roots are: \n");


realPart = -b / (2 * a);
imaginaryPart = sqrt(-discriminant) / (2 * a);
printf("root 1 = %.2lf +%.2lfi \n", realPart, imaginaryPart);
printf("root 2 = %.2lf -%.2lfi \n", realPart, imaginaryPart);
}

return 0;
}

Assignment No. – II Page - 15 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM


Programming for Problem Solving Lab (C)
(ESCS - 291)
CSE – 2nd Sem. – 1st Year

OUTPUT:

****ROOTS OF QUADRATIC EQUATION****

Enter the first coefficients a: 2


Enter the second coefficients b: 10
Enter the third coefficients c: -24
The real and different roots are:
root 1 = 1.77
root 2 = -6.77

Process returned 0 (0x0) execution time : 4.735 s


Press any key to continue.

****ROOTS OF QUADRATIC EQUATION****

Enter the first coefficients a: 9


Enter the second coefficients b: -24
Enter the third coefficients c: 16
The real and equal roots are:
root 1 = root 2 = 1.33
Process returned 0 (0x0) execution time : 9.148 s
Press any key to continue.

****ROOTS OF QUADRATIC EQUATION****

Enter the first coefficients a: 1


Enter the second coefficients b: -3
Enter the third coefficients c: 4
The complex and different roots are:
root 1 = 1.50 +1.32i
root 2 = 1.50 -1.32i

Process returned 0 (0x0) execution time : 6.470 s


Press any key to continue.

Assignment No. – II Page - 16 Md Imrajul Alam, 20/CS/002, </> CS Dept, FIEM

You might also like