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

Chapter5Function Question:

Write a function to determine whether number input is positive or negative number.

#include<iostream> usingnamespacestd; voidnumber();//functionprototype intno;//globalvariable voidmain() { cout<<"Enteranumber:"; cin>>no; number(); } voidnumber() { if(no>=0) cout<<no<<"isthepositivenumber."<<endl; else cout<<no<<"isthenegativenumber."<<endl; }

Question:
Write a function to calculate the addition, subtraction, multiplication and division of numbers.
#include<iostream> using namespace std; int addition(); int subtraction(); int multiplication(); float division(); int no1,no2,result; void main() { cout<<"Enter 2 numbers :"; cin>>no1>>no2; cout<<"The sum of "<<no1<<" and "<<no2<<" : "<<addition()<<endl; cout<<"The multiplication of "<<no1<<" and "<<no2<<" : "<<subtraction()<<endl; cout<<"The product of "<<no1<<" and "<<no2<<" : "<<multiplication()<<endl; cout<<"The division of "<<no1<<" and "<<no2<<" : "<<division()<<endl; cout<<endl; } int addition() { result=no1 + no2; return result; } int subtraction () { result = no1-no2; return result; } int multiplication () { result= no1 * no2; return result; } float division() { result=no1 / no2; return result; }

You might also like