Ahmad Function

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Submitted to: sir prof- Habib

Submitted by:Ahmad sajjad


ARID –NO:22-ARID- 754
Department: BS (CS)-“C.1”
Submission date: 5-Jan-2022
Subject:s
Program fundamentals:

Functions

www.uaar.edu.pk
Q.NO1 WRITE A PROGRAM TO USE FUNCTION TO MAKE
CALULATOR?

#include<upstream>
Using namespace stud;
Void add (int x, int y);
void sub(int x, int y);
void mul(int a,int b);
void divide(int c, int d);
int main(){
int
first_number,second_number,first_number1,second_number1,first_number2,secon
d_number2,first_number3,second_number3;
cout<<"i write a program to make calculator "<<endl;
cout<<"we calculate addition of two number"<<endl;
cout<<"Enter first number "<<endl;
cin>>first_number;
cout<<"Enter second number "<<endl;
cin>>second_number;
add(first_number,second_number);
cout<<"next we calculate subtraction of two number "<<endl;

cout<<"Enter first number "<<endl;


cin>>first_number1;
cout<<"Enter second number "<<endl;
cin>>second_number1;
sub(first_number1,second_number1);
cout<<"next we calculate multiplication of two numbers "<<endl;

cout<<"Enter first number "<<endl;


cin>>first_number2;
cout<<"Enter second number "<<endl;
cin>>second_number2;
mul(first_number2,second_number2);
cout<<"next we calculate dividing of two numbers "<<endl;

cout<<"Enter first number "<<endl;


cin>>first_number3;
cout<<"Enter second number "<<endl;
cin>>second_number3;
divide(first_number3, second_number3);

return 0;
}
void add(int x, int y){
cout<<"addition of two numers ="<<x+y;
cout<<endl;
}
void sub(int x, int y){
cout<<"subtraction of two numbers ="<<x-y;
cout<<endl;
}
void mul(int a,int b){
cout<<"multiplication of two numbers ="<<a * b;
cout<<endl;
}
void divide(int c, int d){
cout<<"dividing of two numbers ="<<c/d;
cout<<endl;
}
OUT PUT
Q.NO2 WRITE A PROGRAM TO USE FUNCTION TO CALCULATE
SQUARE AND CUBE OF THE FUNCTION .
#include<iostream>
using namespace std;
void square(int);
int cube(int);
int main(){
int ret;
cout<<”\n we are calculate square of the function “<<endl;
cout<<”enter number “<<endl;

square(6);
cout<<”\n we are calculate cube of the function “<<endl;
ret=cube(7);
cout<<”cube of the function “<<ret<<endl;
return 0;
}
void square(int n){
cout<<”square of the function =”<<n*n;
}
int cube(int a){
return a*a*a;
}

OUT PUT
Q.NO3 WRITE A PROGRAM TO FIND MAXIMUM AND MINIMUM
VALUE ?
#include<iostream>
using namespace std;
int max(int , int);
int min(int, int);
int main(){
int a=200, b=300,m,mini;
cout<<"we are find maximum value "<<endl;
m=max(a,b);
cout<<"maximum value "<<m<<endl;
mini=min(a,b);
cout<<"minimum value "<<mini<<endl;
return 0;
}
int max(int a, int b){
int result;
if(a>b)
result=a;
else
result=b;
return result;
}
int min(int a, int b){
int ret;
if(a<b)
ret=a;
else
ret=b;
}
OUT PUT
Q.NO4 WRITE A PROGRAM TO SWAPING OF THE FUNCTION ?
#include<iostream>
using namespace std;
void swap(int, int);
int main(){
int a=4,b=3;
cout<<"swaping of two number "<<endl;
swap(a,b);
cout<<"before swaping...a = "<<a<<" b = "<<b<<endl;

return 0;
}
void swap(int a, int b){
int temp;
temp=a;
a=b;
b=temp;
cout<<"after swaping ......"<<endl;
cout<<"a = "<<a<<" b = "<<b<<endl;
}
OUTPUT
Q.NO5 WRITE A PROGRAM TO USE OVERLOADED FUNCTION?
#include <iostream>
using namespace std;

// function with float type parameter


float absolute(float var){
if (var < 0.0)
var = -var;
return var;
}

// function with int type parameter


int absolute(int var) {
if (var < 0)
var = -var;
return var;
}

int main() {

// call function with int type parameter


cout << "Absolute value of -5 = " << absolute(-5) << endl;

// call function with float type parameter


cout << "Absolute value of 5.5 = " << absolute(5.5f) << endl;
return 0;
}
Output:

You might also like