1st Year
1st Year
1st Year
Trishal, Mymensingh
Lab Report.
Course code:CSE-102
Submitted to:
Rubya Shahrian
Assistant Professor
Submitted By:
Ariful Islam
Roll:19102039
Session:2018-19
Reg no:7759
Algorithm:
Step 1:Start.
Step 6:Stop.
Flow chart:
Start
Read a,b ,c
No Yes
Is
a>b
Yes No No Yes
Is a>c
Is
b>c
b c a
greatest greatest greatest
Stop
Code:
#include <stdio.h>
int main()
int a,b,c;
scanf(“%d %d %d”,&a,&b,&c);
if(a>b)
else
Return 0;
Result:
9 is the largest
Discussion:
In this experiment I have experienced the use of nested if..else.This make me understood how to
use logical nested if…else operation which helped me to make short my code.
Problem no: 2
Algorithm:
step1 : Start
step2 : Read number num
step3 : [initialize]
x=1
step4 : Repeat step 4 through 10 until num>=x
step5 : [initialize]
y=1
step6 : Repeat step 6 through 8 until y<=n
step7 : print *
step8 : x=x+1
step10: y=y+1
step11 : stop
Flowchart:
#include<stdio.h>
int main() {
int x,y,n;
scanf("%d", &n);
printf("* ");
printf("\n");
return 0;
}
Result:
**
* **
Discussion:
This experiment has experienced me the use of while loop with the logic of printing triangle
shape.This learning will help me to understand the mechanism of printing different shapes.
Problem No: 3
Algorithm:
step1: Start
step2: Read number num
step3: [initialize]
r=1
step4: Repeat step 4 through 10 until num>=r
step5: [initialize]
c=1
step6: Repeat step 6 through 8 until c<=r
step7: print */#
step8: c=c+1
[end of loop step6]
step9: go to next line
step10: r=r+1
[end of loop step4]
step11: stop
Flowchart:
Code:
#include <stdio.h>
int main() {
int x,y,n;
scanf("%d", &n);
printf("\n");
return 0; }
Result:
* *
* * *
Discussion:
This experiment has experienced me the use of while loop with the logic of printing triangle
shape.This learning will help me to understand the mechanism of printing different shapes.
Problem No: 4
Algorithm:
Step 1. Start
Step 2. Read the coefficients of the equation, a, b and c from the user.
Step 6. Else:
Step 7:Stop
Flowchart:
Code:
#include <math.h>
#include <stdio.h>
int main() {
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
else if (discriminant == 0) {
else {
realPart = -b / (2 * a);
return 0;
Result:
2.3
4
5.6
Discussion:
This experiment has experienced me to solving the math equation with computer programming.
In this program, the sqrt() library function is used to find the square root of a number.
Problem No: 5
Problem Name:
Algorithm:
Step 1: Start
Step 2: You've been given the variable celsius, which represents a temperature in degrees Celsius
Step 5: To convert the Celsius temperature to Fahrenheit, use the above-mentioned procedure.
Step 6: Stop
Flowchart:
Code:
#include<stdio.h>
void main()
float celsius,fahrenheit;
scanf("%f",&fahrenheit);
celsius=(fahrenheit - 32)*5/9;
Result:
Celcious:37.00
Discussion:
This experiment experienced me to play with number by c programming. By this program I have
learnt to convert temperature wich will help me to apply this procedure in any sector.
Problem No: 6
Step 1 : start
Step 8 : stop.
Flowchart:
Start
Stop
Code:
#include <stdio.h>
int main(void)
int num;
scanf("%d",&num);
return 0;
Result:
Enter your mark:
60
Discussion:
This problem experienced me find the grade which help me to find out definite result from multiple
choice.I have used if else statement to complete this procedure.
Problem No: 7
Algorithm:
Step 1 : start
Step 8 : stop.
Flowchart:
Star
t
Stop
Code:
#include<stdio.h>
int main()
{
int score;
switch( score / 10 )
{
case 10:
case 9:
printf("Grade: A");
break;
case 8:
printf("Grade: B");
break;
case 7:
printf("Grade: C");
break;
case 6:
printf("Grade: D");
break;
case 5:
printf("Grade: E");
break;
default:
printf("Grade: F");
break;
return 0;
}
Result:
Enter Score:
90
Discussion:
This problem experienced me find the grade which help me to find out definite result from multiple
choice.I have used if else statement to complete this procedure.
Problem No: 8
Algorithm:
Step1:Start
Step2:Start loop
1.if true,break
2.if false,step 2
Step3:Stop
Flowchart:
False True
Condi
tion break
to
break
Code:
#include <stdio.h>
int main() {
int i;
scanf("%lf", &number);
break;
sum += number;
return 0;
Result:
3
4
Sum=15
Discussion:
This experiment has experienced me the use of break statement.Break statement is a logical statement
which stop the execution of program with given logic by programmer.
Problem No: 9
Algorithm:
Step1:start
Step2:Start loop
2.if true,continue
Step3:stop
Flowchart:
Code:
#include <stdio.h>
int main() {
int i;
scanf("%lf", &number);
continue;
sum += number;
return 0;
Result:
2.4 6 7 8 9 0 6 4 3 6 8.8 8
29.7
Discussion:
This experiment has experienced me the use of continue statement.Continue statement is a logical
statement which the execute the program with given logic by programmer.
Problem No: 10
Algorithm:
Step1: start
Step2: 1.Level1
2.Level2
3.Level3
Step3:goto Level3
Step4:execution of statement 3
Step5:Stop.
Flowchart:
Code:
#include <stdio.h>
int main()
{
int sum=0;
sum = sum+i;
if(i==5){
goto addition;
addition:
printf("%d", sum);
return 0;
Result:
15
Discusssion:
This experiment ecperienced me on about goto statement. GoTo (goto, GOTO, GO TO or other case
combinations, depending on the programming language) is a statement found in many computer
programming languages. It performs a one-way transfer of control to another line of code; in contrast a
function call normally returns control.
Problem No: 11
Algorithm:
Step1:start
Step2:Input the start and end numbers.
Step3:Initialize sum = 0.
Step5:sum = sum + i
Step6:Print "sum"
Step7:stop
Flowchart:
Code:
#include <stdio.h>
Int main()
Int I,s=0,n;
scanf(“%d”,&n);
for(i=1;i<=n;I++)
s=s+I;
}
Printf(“%d”,s);
Return 0;
Result:
15
Discussion:
This experiment has experienced me on how to find range of the series of the value by using for loop.
Problem no: 12
Algorithm:
Step1:Start
Step3:calculate I=prn
Step5:stop
Flowchart:
Start
Calculate I=Prn
Print I
Stop
Code:
#include <stdio.h>
Int main()
float P,I,r,n;
scanf(“%f %f %f”,&P,&r,&n);
P=Irn;
Printf(“%f”,I);
return 0;
}
Result:
1000
0.1
100
Discussion:
This experiment has experienced me on how to calculate interest using simple interest equation I=Prn.
Problem No: 13
Algorithm:
Step1:start
Step5:stop
Flowchart:
start
Read x,n
Yes No For(i=
0;i<n)
a=pow(x,i)
s=s+a
Print s
stop
Code:
#include <stdio.h>
Int main()
Int x,n,a,i,s=0;
Scanf(%d %d”,&x,&n);
for(i=0;i<n;i++)
a=pow(x,i);
s+=a;
printf(“%d”,s);
return 0;
Result:
2 3
Discussion:
This experiment has experienced me on how to calculate the multiple power series value by using for
loop.This will help me to proper control on for loop.
Problem No: 14
Problem Name: Write a program to process loan application and to sensation loan.
Algorithm:
Step1:Start
Step4:if false
1.proceed
Step5:stop.
Flowchart:
start
If(loan
&&loa
n2)
start
Code:
#include <stdio.h>
Int main()
Scanf(“%d %d”,&loan1,&loan2);
If(loan1&&loan2)
Else
Return 0;
Result:
Discussion:
This experiment has experienced me on binary operation with if else logical statement which will help to
make down any logic
Problem No: 15
Problem Name: Write a program to print ODD numbers from 1 to N using while loop.
Algorithm:
Step 1: Start .
Step 3: Input n
Step 6:End
Flowchart:
Start
x=1
Input n
No
x<=n End
Yes
No
x=x+1 x%2!=0
Yes
Program code:
Print x
#include<stdio.h>
int main()
{
int x=1,n;
printf("Enter a number:");
scanf("%d",&n);
while(x<=n){
if(x%2 != 0)
printf("%d\n",x);
x++;
return 0;
Results :
Input: 7
Output : 1 3 5 7
Discussion : We have successfully run a program which have displayed odd numbers
Problem No: 16
Problem Name: Write a program to print EVEN numbers from 1 to N using while loop.
Algorithm:
Step 1: Start .
Step 2: Read two integer value
Step 3: Input n
Step 6:End
Flowchart:
Start
x=1
Input n
Program code:
#include<stdio.h>
int main()
int x=1,n;
printf("Enter a number:");
scanf("%d",&n);
while(x<=n){
if(x%2 == 0)
printf("%d\n",x);
x++;
return 0;
Results :
Input: 10
Output : 2 4 6 8 10
Discussion : We have successfully run a program which have displayed even numbers
Problem No: 17
Problem Name: Write aprogram to print all uppercase alphabets using while loop
Algorithm:
Step 1: Start .
Step 5: alphabets=alphabets+1
Step 6:End
Flowchart:
Start
alphabets= ‘A’
No
Alphabets<= End
‘Z’
Yes
alphabets=alphab
Print alphabets
ets+1
Program code:
#include<stdio.h>
int main()
char alphabets='A';
while(alphabets<='Z')
printf("%c\n",alphabets);
alphabets++;
Results :
Output : A B C D E F G H J K L M N O P Q R S T U V W X Y Z
Discussion : We have successfully run a program which have displayed uppercase alphabets
Problem No: 18
Problem Name: Write aprogram to print all lowercase alphabets using while loop
Algorithm:
Step 1: Start .
Step 5: alphabets=alphabets+1
Step 6:End
Flowchart:
Start
alphabets= ‘z’
No
Alphabets<= End
‘z’
Yes
alphabets=alphab
Print alphabets
ets+1
Program code:
#include<stdio.h>
int main()
char alphabets='a';
while(alphabets<='z')
printf("%c\n",alphabets);
alphabets++;
return 0;
Results :
Output : a b c d e f g h I j k l m n o p q r s t u v w x y z
Discussion : We have successfully run a program which have displayed lowercase alphabetes
Problem No: 19
Problem Name: Write a program to print numbers from 1 to N using for loop.
Algorithm:
Step 1: Start
Step 2: Read two integer type value
Step 3: Input n
Step 4: Set =1
Step 5: Repeat step 6&7 until x<=n reach
Step 6: Print x
Step 7: Compute x=x+1
Step 8: End
Flowchart
Start
Input n
x=1
False
x<=n End
True
Print x
x=x+1
Program code:
#include<stdio.h>
int main()
int x,n;
scanf("%d",&n);
printf("%d\n",x);
return 0;
Results :
Input: 10
Output : 1 2 3 4 5 6 7 8 9 10
Problem No: 20
Step 1: Start .
Step 5: x=x+1
Step 6:End
Flowchart:
Start
x=1
No
End
x<=10
Yes
x=x+1
Print x
Program code:
#include<stdio.h>
int main()
int x=1;
while( x<=10)
{
printf("%d\n",x);
x++;
return 0;
Results :
Input: 10
Output : 1 2 3 4 5 6 7 8 9 10
Discussion : We have successfully run a program which have displayed numbers from 1 to n
Problem No: 21
Problem Name: write program to print square, cube and square root of all numbers from 1 to n
Algorithm:
Step 1: Start .
Step 2: Read four integer type value and one float type value
Step 5:End
Flowchart :
Start
Input n
x=1
Fasle
x<=n End
True
s=x*x
c=x*x*x
r=sqrt((double) x)
Program code:
#include<stdio.h>
#include<math.h>
int main()
int x,n,s=1,c=1;
float r;
scanf("%d",&n);
for(x=1;x<=n;x++)
{
s=x*x;
c=x*x*x;
r=sqrt((double) x);
printf("%d %d %.2f\n",s,c,r);
return 0;
Results :
Input: 3
1 1 1.00
4 8 1.41
9 27 1.73
Discussion : We have successfully run a program which have displayed square ,cube and
squareroot from 1 to n
Problem No: 22
Problem Name: Write a program to read age of 15 person and count total Baby age, School age and Adult
age
Algorithm:
Step 1: Start .
Step 5: x=x+1
Step 6:End
Flowchart :
Start
count =0
Yes
Input age
End
Yes
If age>=0and Baby++
age<=5
No
yes
If
scl++
age>=0and
age<=5
No
#include<stdio.h>
int main()
int age;
int cnt_baby=0,cnt_school=0,cnt_adult=0;
int count=0;
while(count<15)
scanf("%d",&age);
cnt_baby++;
cnt_school++;
else
cnt_adult++;
count++;
return 0;
}
Result :
4 5 3 7 8 44 34 3 6 9 13 12 15 2 6
Total baby = 7
Discussion : This program successfully takes 15 inputs from user and print the number of
baby age ,school age and adult people among the inputs .
Problem No: 23
Algorithm:
Step 1: Start .
Step 4: Input n
Step 6: Print f
Step 7:End
Flowchart:
Start
Input n
x=1,f=1
False
x<=n Print f
True
End
x=x+1 f=f*x
Program code:
#include<stdio.h>
int main()
int x,n,f=1;
scanf("%d",&n);
for(x=1;x<=n;x++)
f=f*x
printf("Factorial is:%d\n",f);
return 0;
Results :
Input: 4
Output : Factorial is 24
Discussion : We have successfully run a program which have displayed factorial from 1 to n.
Problem No: 24
Problem Name: Write a Program to find sum of first N natural number, N must be taken by user
Algorithm:
Algorithm :
Step 1: Start.
Step 7: End.
Flowchart:
Start
Input n
x=1,sum=0
False
x<=n Print sum
True
End
x=x+1 sum=sum+x
Program code:
#include<stdio.h>
int main()
{
int x,n;
int sum=0;
scanf("%d",&n);
sum += x;
printf("%d\n",sum);
return 0;
Result :
number: 10 sum of 1 to 10 is = 55
Discussion : This program successfully takes a input from the user and print the total
summation from 1 to n .
Problem No. : 25
Algorithm:
Step 1: Start .
Step 3: initialize a for loop which will print all the leap years from 1 to n.
Step 4: End.
Flowchart:
Program code:
#include <stdio.h>
int main()
int n,x;
scanf("%d",&n);
printf("%d\n",i);
return 0;
Result :
Discussion : This program successfully takes input from the user and print leap
years from 1 to n.
Problem No. : 26
Problem Name : Write a c program to print all the Even and Odd numer from 1 to N.
Algorithm :
Step 1: Start.
Step 4: Initialize a for loop which will print all the odd numbers from 1 to n.
Step 6: Initialize a for loop which will print all the even numbers from 1 to n.
Step 7: End.
47
Flowchart:
Program code:
#include<stdio.h>
int main()
int n,i;
scanf("%d",&n);
if(i%2==0){
printf("%d\n",i);}
if(i%2!=0){
printf("%d\n",i);}
return 0;
}
Result :
1 357
All EVEN number between 1 and 8 are written below:
2 468
Discussion: The program takes a number as a input from the user and prints all the even
and odd numbers from 1 to the input number successfully.
Problem No: 27
Step 1: Start.
Step 2: Read n value.
Step 3: Initialize count = 0
Step 4:for i = 2 to n
Step 4.1: for j = 1 to i
Step 4.2 : if i % j = 0
Step 4.3 : then increment count
Step 4.4 : if count is equal to 2
Step 4.5 : then print i value
Step 5: End.
Start
Flowchart:
Count=0
Read n
No
for(i=1;i<=n;i++
Yes
No
for(j=2;j<=i\2;j++
Yes
no
No
if(i%j== if(count=
0 =0
yes yes
Print I value
count++
End
Program code:
#include<stdio.h>
int main(){
int i, num, n, count;
printf("Enter the range: \n");
scanf("%d", &n);
printf("The prime numbers in between the range 1 to %d:",n);
for(i = 1;i<=n;i++){
count = 0;
for(j=2;j<=i/2;i++){
if(i%j==0){
count++;
break;
}
}
if(count==0 && i!= 1)
printf("%d ",i);
}
return 0;
}
Result:
Enter the range: 20
The prime numbers in between the range 1 to 20: 2 3 5 7 11 13 17 19