0% found this document useful (0 votes)
3 views

Lab Report

This lab report presents various programming exercises completed as part of a Computer Fundamentals and Programming course. It includes algorithms, flow charts, and C code for problems such as finding the greatest of three numbers, calculating interest, solving quadratic equations, and converting temperatures. Each problem is accompanied by sample inputs, outputs, and discussions confirming successful execution.

Uploaded by

Marshia Mohana
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lab Report

This lab report presents various programming exercises completed as part of a Computer Fundamentals and Programming course. It includes algorithms, flow charts, and C code for problems such as finding the greatest of three numbers, calculating interest, solving quadratic equations, and converting temperatures. Each problem is accompanied by sample inputs, outputs, and discussions confirming successful execution.

Uploaded by

Marshia Mohana
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Lab Report

Lab Report

Course Title: Computer Fundamental & Programing


Basic Lab
Course Code: CSE 102

Submitted to
Rubya Shaharin
Assistant Professor
Computer Science & Engineering Department
Jatiya Kabi Kazi Nazrul Islam University

Submitted by
Marshia Minhaj Mohana
Roll: 20102041
Reg No: 8872
Session: 2019-20
Computer Science & Engineering Department
Jatiya Kabi Kazi Nazrul Islam University

Submission Date: December 15, 2021

1
Table of Contents

SL No Problem Name Page No


01 Find the greatest amongst three numbers 3

02 Calculating Interest 5

03 Find the roots of ax2+bx+c=0 7

04 Convert Fahrenheit to Celsius and Celsius to 9


Fahrenheit
05 Write a program to process loan application 12
and to sanction
06 Write a program to display pyramid 15

07 Write a program to display triangle 18

08 Find grade using switch 20

09 Find grade using if else 23

10 Use of break statement 26

11 A Program to evaluate the series: 29


1 n
1−x = 1+x+x2+x3+……..+x

12 Use of continue statement 32

13 Use of goto statement 35

14 Find the range of a series of values 38

2
Problem No: 1

Problem Name: Find the greatest amongst three numbers

Algorithm:
Step 1: Start
Step 2: Input the three numbers a,b,c
Step 3: Check if a is greater than b
Step 4: If it is true than check a is greater than c
Step 4.1: If true print that the greatest number is a
Step 4.1: If false print that the greatest number is c
Step 5: If it is true than check b is greater than c
Step 5.1: If true print that the greatest number is b
Step 5.1: If false print that the greatest number is c
Step 6: End
Flow Chart:

Start

Input a,b,c

No Yes
Is a>b?

Is b>c? No No
Is a>c?

Yes Yes

Print a Print b Print c

End

3
Program Code:

#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the three numbers: ");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("The largest number is %d",a);
}
else
{
printf("The largest number is %d",c);
}
}
else
{
if(b>c)
{
printf("The largest number is %d",b);
}
else
{
printf("The largest number is %d",c);
}
}
}

Result:
Input: 3 7 10
Output: The largest number is 10

Discussion: This program takes three numbers as input and shows the largest amongst
them. So we have successfully executed this program.

4
Problem No: 2

Problem Name: Calculating Interest

Algorithm:
Step 1: Start
Step 2: Input the amount of money, interest rate and period
Step 3: Set the year value year=1
Step 4: Initialize a while loop
Step 5: Checking the condition
Step 6: Calculate the interest using the formula –
value= amount+inrate*amount;
Step 7: Print the year and interest value
Step 8: When the number of amount is equal to interest value increase the number of year
Step 9:End

Flow Chart:

Start

Input period, amount, inrate

year = 1

year<=period

value=amount+i
nrate*amount

Print year and Amount=value,


End value year+=1

5
Program Code:
#include<stdio.h>
int main()
{
int period, year;
float amount, inrate, value;
printf("Enter amount, interest rate and period:\n\n");
scanf("%f%f%d",&amount,&inrate,&period);
printf("\n");
year = 1;
while(year <= period)
{
value=amount+inrate*amount;
printf("%2d Rs %8.2f\n",year,value);
amount=value;
year=year+1;
}
}

Result:
Input: 10000 0.14 5
Output: 1 Rs 11400.
2 Rs 12996.00
3 Rs 14815.44
4 Rs 16889.60
5 Rs 19254.15

Discussion: We have successfully executed this program.

6
Problem No: 3

Problem Name: Find the roots of a quadratic equation: ax2+bx+c=0

Algorithm:
Step 1: Start
Step 2: Input the three numbers a, b, c
Step 3: Identify the discriminant = (b*b)-(4*a*c)
Step 4: Initialize the if condition
Step 4.1: If the discriminant is less than 0 go to step 5
Step 4.2: Else identify root1=(-b+sqrt(discriminant))/(2*a) and root2=(-b-
sqrt(discriminant))/(2*a) and go to step 6
Step 5: Print that the roots are imaginary
Step 6: Print root1 and root2
Step 7: End

Flow Chart:

Start

Input a,b,c

discriminant=b*b - 4 *a*c

Yes No
If discriminant <0

root1=(b+sqrt(discriminant))/(2*a);
root2=(-b-sqrt(discriminant))/(2*a);

Yes
Print Roots are Print Root1 and
imaginary Root2

End

7
Program Code:
#include<stdio.h>
int main()
{
float a,b,c,discriminant,root1,root2;
printf("Enter values of a,b,c: \n");
scanf("%f%f%f",&a,&b,&c);
discriminant=b*b - 4 *a*c;
if(discriminant<0)
{
printf("Roots are imaginary\n");
}
else
{
root1=(-b+sqrt(discriminant))/(2*a);
root2=(-b-sqrt(discriminant))/(2*a);
printf("Root 1 = %5.2f\nRoot 2 = %5.2f\n",root1,root2);
}
}

Result:
Input: 16 49 -100
Output: Root 1 = 1.40
Root 2 = -4.46

Discussion: In this program the roots of any given quadratic equation can be easily found by
−b+ √((b∗b)−4 ac ) −b+ √((b∗b)−4 ac )
applying the formula root1= and root2= with the help
2a 2a
of mathematical functions. We have successfully executed this program.

8
Problem No: 4

Problem Name: Convert Fahrenheit to Celsius and Celsius to Fahrenheit

4.1: Fahrenheit to Celsius

Algorithm:
Step 1: Start
Step 2: Input a temperature in fahrenheit
Step 3: Identify Celsius = (fahrenheit-32)*5/9
Step 4: Print the Celsius temperature
Step 5: End

Flow Chart:

Start

Input fahrenheit

celsius=(fahrenheit-32)*5/9

Print Celsius

End

9
Program Code:
#include<stdio.h>
int main()
{
float celsius,fahrenheit;
printf("Enter temperature in Fahrenheit: ");
scanf("%f",&fahrenheit);
celsius=(fahrenheit-32)*5/9;
printf("\nCelsius = %.3f",celsius);
return 0;
}

Result:
Input: 186.00
Output: Celsius = 85.556

Discussion: This program will convert any temperature from Fahrenheit to Celsius by
applying the formula celsius=(fahrenheit-32)*5/9. We have successfully executed this
program.

4.2: Celsius to Fahrenheit

Algorithm:
Step 1: Start
Step 2: Input a temperature in celsius
Step 3: Identify Fahrenheit = (celsius*9/5)+32
Step 4: Print the Fahrenheit temperature
Step 5: End

10
Flow Chart:

Start

Input celsius

Fahrenheit = (celsius*9/5)+32

Print Fahrenheit

End

Program Code:
#include<stdio.h>
int main()
{
float celsius,fahrenheit;
printf("Enter temperature in celsius: ");
scanf("%f",&celsius);
fahrenheit=(celsius*9/5)+32;
printf("\nFahrenheit=%.3f",fahrenheit);
}

Result:
Input: 85.556
Output: Fahrenheit = 186.00

Discussion: This program will convert any temperature from Celsius to Fahrenheit by
applying the formula Fahrenheit = (celsius*9/5)+32. We have successfully executed this
program.

11
Problem No: 5

Problem Name: Write a program to process loan application and to sanction loans

Algorithm:
Step 1: Start
Step 2: Declare two variable sancloan and sum
Step 3: Input the value of loan1, loan2, loan3
Step 4: Assign sum = loan2 + loan3
Step 5: checking the if condition
Step 5.1: If loan1>0 then sancloan=0 and go to Step 6
Step 5.2: Else if sum>MAXLOAN then sancloan = MAXLOAN – loan2 and go to Step 6
Step 5.3: Else sancloan = loan3 and go to Step 6
Step 6: Print sancloan
Step 7: End

12
Flow Chart:
Start

Input loan1, loan2, loan3

sum=loan2+loan3

Yes
If(loan1>0) sancloan=0

No

else
if(sum>MAXLOAN)
No Yes

sancloan=MAXLOAN-
sancloan=loan3
loan2

Print sancloan

End

13
Program Code:
#include<stdio.h>
#define MAXLOAN 50000
int main()
{
long int loan1,loan2,loan3,sancloan,sum;
printf("Enter the value of prefious two loans:\n");
scanf("%ld %ld",&loan1,&loan2);
printf("Enter the value of new loan:\n");
scanf("%ld",&loan3);
sum=loan2+loan3;
if(loan1>0)
{
sancloan=0;
}
else if(sum>MAXLOAN)
{
sancloan = MAXLOAN - loan2;
}
else
{
sancloan = loan3;
}
printf("Previous loans pending: \n%ld \n%ld",loan1,loan2);
printf("Loan requested: %ld\n",loan3);
printf("Loan sanctioned: %ld\n",sancloan);
}

Result:
Input:
Enter the value of prefious two loans:
0 10000
Enter the value of new loan:
20000
Output:
Previous loans pending:
0 10000
Loan requested: 20000
Loan sanctioned: 20000

Discussion: We have successfully executed this program. Because here the three loans will
be taken as input and the sanction of the loans will be shown as output.

14
Problem No: 6

Problem Name: Write a program to display pyramid

Algorithm:
Step 1: Start
Step 2: Input a number n, row and column
Step 3: Initialize a for loop
Step 3.1: If col<=(n-row) goto step 4
Step 3.2: If col<=((2*row)-1) goto step 5
Step 4: Print (“ “)
Step 5: Print *
Step 6: Print a new line
Step 7: End

15
Flow Chart:

Start

Input n

No
row <= n

Yes

No
col<=(n-row)

Yes
No

PrintNo
“ “ Col++

col<=(2*row)- Yes
1

Print *

Col++

End

16
Program Code:
#include<stdio.h>
int main()
{
int row,col,n;
printf("Enter the value of n: ");
scanf("%d",&n);
for(row=1;row<=n;row++)
{
for(col=1;col<=(n-row);col++)
{
printf(" ");
}
for(col=1;col<=(2*row)-1;col++)
{
printf("*");
}
printf("\n");
}
}

Result:

Discussion: We have successfully executed this program.

17
Problem No: 7
Problem Name: Write a program to display triangle
Algorithm:
Step 1: Start
Step 2: Input a number n
Step 3: read two variables row, col
Step 4: Initialize a for loop
Step 4.1: If row<=n then goto step 5
Step 4.2: Else go to step 7
Step 5: Initialize an another for loop
Step 5.1: If col<=row then go to step 6
Step 5.2: Else assign row=row+1 and go to step 4
Step 6: Print * in col, assign col=col+1 and go to step 4
Step 7: End
Flow Chart:

Start

Input n
No
row<=n

Yes

col=0

No
row=row+1 col<=row

Yes

Print * Yes
, col col=col+1

End

18
Program Code:

#include<stdio.h>
int main()
{
int row,col,n;
printf("Enter the value of n: ");
scanf("%d",&n);
for(row=1;row<=n;row++)
{
for(col=1;col<=row;col++)
{
printf("*",col);
}
printf("\n");
}
}

Result:

Discussion: We have successfully executed this program.

19
Problem No: 8

Problem Name: Find grade using switch

Algorithm:
Step 1: Start
Step 2: Input the number where the range is 0 to 100
Step 3: switch(num)
Step 3.1: case 100, case 90 and case 80
Print Grade A+
Break
Step 3.2: case 70
Print Grade A
break
Step 3.3: case 60
Print Grade A-
break
Step 3.4: case 50
Print Grade B
break
Step 3.5: case 40
Print Grade C
break
Step 3.6: default and Grade F
Step 4:End

20
Flow Chart:

Start

Input num

Switch(num)

Yes Grade A+;


Case 100, 90 & 80
break;

No
Yes Grade A;
Case 70 break;
No

Yes Grade A-;


Case 60
break;
No

Yes Grade B;
Case 50
break;
No

Yes Grade C;
Case 40
break;
No
Yes Grade F;
default
break;

End

21
Program Code:
#include<stdio.h>
int main()
{
int num;
printf("Enter the number(0 - 100): ");
scanf("%d",&num);
switch(num)
{
case 100:
case 90:
case 80:
printf("Grade: A+\n");
break;
case 70:
printf("Grade: A\n");
break;
case 60:
printf("Grade: A-\n");
break;
case 50:
printf("Grade: B\n");
break;
case 40:
printf("Grade: C\n");
break;
default:
printf("Grade: F\n");
break;
}
}

Result:
Input: Enter the number: 60
Output: Grade A-

Discussion: The number range is taken from 0 to 100 in this program. The grades for
different number will be shown here by using switch function. We have successfully
executed this program.

22
Problem No: 9

Problem Name: Find grade using if else

Algorithm:
Step 1: Start
Step 2: Input num
Step 3: If num>=80 go to step 4
Step 3.1: Else if num>=70 go to step 5
Step 3.2: Else if num>=60 go to step 6
Step 3.3: Else if num>=50 go to step 7
Step 3.3: Else if num>=40 go to step 8
Step 3.4: Else go to step 9
Step 4: Print Grade A+
Step 5: Print Grade A
Step 6: Print Grade A-
Step 7: Print Grade B
Step 8: Print Grade C
Step 9: Print Grade F
Step 10:End

23
Flow Chart:

Start

Input num

Yes Grade A+
If num>=80

No

Yes
If num>=70 Grade A

No

Yes
If num>=60 Grade A-

No

Yes
If num>=50 Grade B

No

If num>=40 Yes Grade C

No
Grade F

End

24
Program Code:
#include<stdio.h>
int main()
{
int num;
printf("Enter the number(0 - 100): ");
scanf("%d",&num);
if(num>=80)
printf("Grade: A+\n");
else if(num>=70)
printf("Grade: A\n");
else if(num>=60)
printf("Grade: A-\n");
else if(num>=50)
printf("Grade: B\n");
else if(num>=40)
printf("Grade: C\n");
else
printf("Grade: F\n");
}

Result:
Input: Enter the number: 40
Output: Grade C

Discussion: The number range is taken from 0 to 100 in this program. The grades for
different number will be shown here by using If-else ladder. We have successfully executed
this program.

25
Problem No: 10

Problem Name: Use of break statement

Algorithm:
Step 1: Start
Step 2: Initialize a for loop
Step 3: Checking the if condition
Step 3.1: if m<1000 then go to step 8
Step 3.2: Else go to step 4
Step 4: Input the value of x
Step 5: Check the if condition
Step 5.1: If(x<0) then break and exit from the loop and go to step 6
Step 5.2: Else identify sum+=x and goto step 5
Step 6: Identify Average=sum/(float)(m-1)
Step 7: Print value, sum, average
Step 8: End

26
Flow Chart:
Start

No
m<1000

Yes

Input x

Yes
If (x<0)

Average=sum/(float)(m-1)
No

Sum+=x

m++ Print sum, average

End

27
Program Code:
#include<stdio.h>
int main()
{
int m;
float x, sum, average;
printf("This program computes the average of a set of numbers\n");
printf("Enter values one after another\n");
printf("Enter a negative number at the end\n");
sum=0;
for(m=1;m<=1000;m++)
{
scanf("%f",&x);
if(x<0)
break;
sum+=x;
}
average=sum/(float)(m-1);
printf("\n");
printf("Sum = %f\n",sum);
printf("Average = %f\n",average);
}

Result:
This program computes the average of a set of numbers
Enter values one after another
Enter a negative number at the end
Input: 21 23 24 22 26 22 -1
Output:
Sum = 138.000000
Average = 23.000000

Discussion: The number of values, sum, average of the given numbers will be shown in this
program. We have successfully executed this program.

28
Problem No: 11

Problem Name: A program to evaluate the series:


1
1−x = 1+x+x2+x3+……..+xn

Algorithm:
Step 1: Start
Step 2: Read an integer n and four double variable x, term, sum, m
Step 3: Input x
Step 4: Initialaze a for loop
Step 4.1: Assign sum=sum+term
Step 4.2: Check the if condition
Step 4.2a: If term<=m goto step 6
Step 4.2b: Else go to step 4.3c
Step 4.2c: Assign term*=x and go to step 4
Step 5: Print n is not sufficient to achieve the desired accuracy
Step 6: Print the sum
Step 7: End

29
Flow Chart:

Start

Input x

No

n<=100

Yes

Sum+=term Print n is not


sufficient

No
term<=m Print the sum

Yes

Term*=x & n+1

End

30
Program Code:
#include<stdio.h>
#include<math.h>
int main()
{
double x,term,sum=0,m=0.0001;
int n;
printf("Enter the value of x: ");
scanf("%lf",&x);
for(term=1,n=1;n<=100;n++)
{
sum+=term;
if(term<=m)
goto output;
term*=x;
}
printf("n is not sufficient to achieve the desired accuracy\n");
goto end;
output:
printf("Exit from loop\n");
printf("Sum = %lf\n",sum);
printf("No. of terms = %d\n\n",n);
end:
return 0;
}

Result:
Input: .97
n is not sufficient to achieve the desired accuracy

Discussion: We have successfully executed this program.

31
Problem No: 12

Problem Name: Use of continue statement

Algorithm:
Step 1: Start
Step 2: Declare two values count=0,negative=0.
Step 3: Initialize a while loop
Step 3.1: If count<=100 then go to step 4
Step 3.2: Else go to step 8
Step 4: Input number and Checking the if condition
Step 4.1: If number=9999 then break and go to step 8
Step 4.2: Else if number <0 then increase negative++ and go to step 6
Step 4.3: Else assign the value of sqroot=sqrt(number) and goto step 5
Step 5: Print the square root of the number, assign count++ and go to step 3
Step 6: Print the negative item and goto step 3
Step 8: End

32
Flow Chart:

Start

count=0, negative=0

No
Start Start

count<=100

Yes
Start

Input number

Yes
Start number=9999

No
Start

Yes
number<0 Start negative++

Sqroot=sqrt(number)

Print negative

Print number, sqroot count++

End

33
Program Code:
#include<stdio.h>
#include<math.h>
int main()
{
int count, negative;
double number, sqroot;
printf("Enter 9999 to STOP\n");
count = 0,negative = 0;
while(count<=100)
{
printf("Enter a number: ");
scanf("%lf",&number);
if(number==9999)
break;
else if(number<0)
{
printf("Number is negative\n");
negative++;
continue;
}
else
{
sqroot=sqrt(number);
printf("Number = %lf\nSquare root = %lf\n", number, sqroot);
count++;
}
}
printf("Negative item = %d\n", negative);
printf("End of data\n");
}

Result:
Enter 9999 to STOP
Enter a number: 56
Number = 56.000000
Square root = 7.483315
Enter a number: 9
Number = 9.000000
Square root = 3.000000
Discussion: We have successfully executed this program.

34
Problem No: 13

Problem Name: Use of goto statement

Algorithm:
Step 1: Start
Step 2: Input the number x
Step 3: Initialize a read level
Step 4: Checking the if condition
Step 4.1: if x<0 then go to step 6
Step 4.2: Else identify y=sqrt(x) and go to step 7
Step 5: Increase the count value and checking the if condition
Step 5.1: If(count<=5) then go to step 3
Step 5.2: Else go to Step 8
Step 6: Print that the value is negative
Step 7: Print the value of x and y
Step 8: End

Flow Chart:
Start

Input x

35
Label read:

Yes No
If x<0

y=sqrt(x)

Print the value is Print the value of


count++
negative x,y

Yes If(count No
End
<=5)

Program Code:
#include<stdio.h>
#include<math.h>
int main()
{
double x,y;
int count=1;
printf("Enter five real values in a line\n");
read:
scanf("%lf",&x);

36
printf("\n");
if(x<0)
{
printf("value %d is negative\n",count);
}
else
{
y=sqrt(x);
printf("%lf\t %lf\n",x,y);
}
count++;
if(count<=5)
goto read;
}
Result:
Input:
Enter five real values in a line
100 35.75 45.25 99 -8

Output: 100.000000 10.000000


35.750000 5.979130
45.250000 6.726812
99.000000 9.949874
value 5 is negative
End of computation
Discussion: We can find the roots of the given numbers from this program. We have
successfully executed the program.

Problem No: 14

Problem Name: Find the range of a series of values

Algorithm:
Step 1: Start
Step 2: Input value
Step 3: Declare an input label
Step 4: Check the if condition
Step 4.1: If value<0 go to output lebel and jump to step 8
Step 4.2: Else increase the count value and go to step 5
Step 5: Checking the if condition
Step 5.1: If count==1 then identify high = low = value and go to step 6
Step 5.2: else if(value>high) then identify high=value and go to step 6
37
Step 5.3: else if(value<low) then identify low=value and go to step 6
Step 5.4: Else go to Step 6
Step 6: Identify sum = sum+value and goto step 7
Step 7: Goto input label and then jump to step 2
Step 8: Identify Average=(sum/count), Range=high-low
Step 9: Print total,highest, lowest,range and average of numbers
Step 12: End

Flow Chart:

Start

Sum=0, Count=0

Input
Input a number
value

Yes
If value<0 38
No
goto output

No No

Output

Yes Yes Yes

high=value

sum=sum+value

No

End

Program Code:
#include<stdio.h>
int main()
{
int count=0;
float value,high,low,sum=0,average,range;
printf("Enter numbers in a line: input a negative number to end\n");
input:
scanf("%f",&value);
if(value<0) goto output;
count++;
if(count==1)
high = low = value;
else if(value>high)
high=value;
else if(value<low)
low=value;
sum=sum+value;
39
goto input;
output:
average=sum/count;
range=high-low;
printf("Total values : %d\n",count);
printf("Highest Value: %f\nLowest Value: %f\n",high,low);
printf("Range: %f\nAverage: %f\n",range,average);
}

Result:
Input:
Enter numbers in a line: input a negative number to end
12 34 67 45.50 35 70 100 49.50 62.50 43 -1
Output:
Total values : 10
Highest Value: 100.000000
Lowest Value: 12.000000
Range: 88.000000
Average: 51.849998

Discussion: This program shows the total, highest, lowest, range and average of the given
numbers. We have successfully executed this program.

40

You might also like