Laboratory Report-2
Laboratory Report-2
Laboratory Report-2
Number
Experiment Title Write a C++ program to calculate the GCD
of two numbers using recursive functions.
Usecall-by value as a method of passing
parameters to the function
Date of 24/01/2023
Experiment
Date of 10/03/2023
Submission
Theory:-
Flow Diagram / Algorithm:-
Code:-
include<iostream>
using namespace std;
int gcd(int a,int b);
int main( )
{
cout<<"Name :SRINJOY SAHOO Rollno. : 2130083 \n";
cout<<"Enter two number : ";
int a,b; cin>>a>>b;
int c=gcd(a,b);
cout<<"The GCD is :"<<c<<endl;
}
int gcd(int a,int b){ if(a==0 || b==0) return 0;
else if(a == b){
return a;
}
else if(a>b){ return gcd(a-b,b);
}
else{
return gcd(a,b-a);
}
}
Results/Output:-
Remarks:-
Experiment 02-2
Number
Experiment Title Write a C++ program to interchange the
largest and the smallest numbers in the
arrayusingfunctions. Use call-by reference
as a method of passing parameters to the
function.
Date of 24/01/2023
Experiment
Date of 10/03/2023
Submission
Theory:-
Flow Diagram / Algorithm:-
Results/Output:-
Code:-#include<iostream>
using namespace std;
int area(int);
int area(int,int);
float area(float);
float area(float,float);
int main()
{
string name;
cout << "SRINJOY SAHOO 2130083 \n: ";
int s,l,b;
float r,bs,ht;
cout<<"Enter side of a square:";
cin>>s;
cout<<"Enter length and breadth of rectangle:";
cin>>l>>b;
cout<<"Enter radius of circle:";
cin>>r;
cout<<"Enter base and height of triangle:";
cin>>bs>>ht;
cout<<"Area of square is "<<area(s);
cout<<"\nArea of rectangle is "<<area(l,b);
cout<<"\nArea of circle is "<<area(r);
cout<<"\nArea of triangle is "<<area(bs,ht);
}
int area(int s)
{
return(s*s);
}
int area(int l,int b)
{
return(l*b);
}
float area(float r)
{
return (3.14 * r * r);
}
float area(float bs, float ht)
{
return ((bs * ht) / 2);
}
Results/Output:-
Signature of the
Student