Friday, February 25, 2011

PROGRAMMING EXERCISE 1

Sum and Minus Two Integers

#include<iostream.h>
main( )
{
//declare variable
float sum,minus,num1,num2;
//input1
cout<<''num1='';
cin>>num1;
//input2
cout<<''num2='';
cin>>num2;
//formula
sum=num1+num2;
minus=num2-num1;
//output
cout<<''sum=''<<sum;
cout<<''minus=''<<minus;
return 0;
}

Multiply Two Integers

#include<iostream.h>
main()
{

//Declare variable
int multiply,num1,num2;

//Input num1
cout<<"Enter num1 =";
cin>>num1;

//Input num2
cout<<"Enter Num 2 =";
cin>>num2;

//Formula
multiply=num1*num2;

//Output
cout<<"mutiply= "<<mutiply;
return 0;
}

Fahrenheit Convert to Celsius

#include<iostream.h>
main( )

{
//declare variable  
float celcius;
float Fahrenheit;

//Input Fahrenheit

cout<<"Enter farenheit=";
cin>>farenheit;
//Formula
celcius=5/9*(farenheit -32);
//Output
cout<<"farenheit= "<<farenheit;
cout<<"celcius= "<<celcius;


return 0;
}


Celsius Convert to Fahrenheit

#include<iostream.h>
main()
{
//declared variable 
float celcius, Fahrenheit;

//Input Celsius
cout<< "Enter celcius=";
cin>> Celsius;

//Formula
farenheit=9/5*(celcius+32);

//Output
cout<<"Celcius="<<celcius;
cout<<"Farenheit="<<farenheit;
return 0;
}

Divide and Modulus Two Integers
                             
#include<iostream.h>
main( )

{
//declare variable
float divide, modulus, Num1, Num2;
//Input 1 
cout<<"Num1= ";
cin>>Num1;
//Input 2
cout<<"Num2= ";
cin>>Num2 ;
//formula
Divide=Num2/Num1;
Modulus=Num1%Num2;
//Output
cout<<"divide="<<divide;
cout<<"modulus="<<modulus;
return 0;
}








No comments:

Post a Comment