You are on page 1of 4

Computer fundamentals and programming

Lab report 3

Name: Ahmed raza


Section: A
Department: EE

Question: 1
Write a code to tell whether a Number is Even or Odd?

Code:
#include<iostream>
using namespace std;
int main()

{
int x,remainder;
cout<<"This program check number is Even or Odd"<<endl;
cout<<"Input number: ";
cin>>x;
remainder=x%2;
if(remainder==0)
{
cout<<"Even";
}
else
{
cout<<"Odd=";
}
return 0;
}

Output:

Description:
The code introduces to the, if else statements which are conditional statements. When the
particular condition is true the results under it are displayed otherwise the statements under else
are displayed. The code uses remainder operator to tell whether the entered number is even or
odd.

Question: 2
Calculator using float

Code:
#include<iostream>
using namespace std;
int main()
{
float a, b,sum,addition,multiplication,division;

cout << "Input value of a= ";


cin >> a;
cout<< "Input value of b= ";
cin >> b;

sum = a + b ;
multiplication=a*b;
division=a/b;
cout<<"Sum= "<<sum<<endl;
cout<<"Multiplication= "<<multiplication<<endl;
cout<<"Division= "<<division<<endl;
return 0;}

output:

Description:
The code is calculator for floating point number which uses basic calculator operations
and uses cin and cout to simply input and output the values.

Question: 3
Grade assignement

Code:
#include<iostream>
using namespace std;
int main()
{
int marks,grade;
cout<<"Input marks: ";
cin>>marks;
if(marks>90)
cout<<"Grade is A";
else if(marks>80 )
cout<<"Grade is B: ";
else if(marks>70)
cout<<"Grade is B+: ";
else if(marks>60)
cout<<"Grade is C : ";
else if(marks>60)
cout<<"Grade is D: ";
else
cout<<"Fail";

return 0;}

Output:

Description:
The code uses else if statement which is used to assign the grades according to the marks
input uses cin and then the grades are assigned according to the condition in front of the if else if
statements when the condition gets true the grade under the condition is printed.

You might also like