LAB TASK 4 Abdullah khalid
LAB TASK 4 Abdullah khalid
PF lab 4
LAB TASK
Program 1;
#include <iostream>
int main(){
int num1,num2;
cout<<"Enter you num1:";
cin>>num1;
cout<<"Enter you num2:"<<endl;
cin>>num2;
if(num1*num1==num2){
cout<<"The number 2 is square of num1"<<endl;
Output;
Algorithm;
Program 2;
#include <iostream>
int main()
{
int a;
cout<<"enter a:";
cin>>a;
if(a>0){
cout<<"a is positive"<<endl;
}
else if(a<0){
cout<<"a is negative"<<endl;
}
else{
cout<<"the number is zero"<<endl;
}
}
Output;
Algorithm;
Program 3;
#include <iostream>
int main(){
int a,b;
cout<<"Enter any number1"<<endl;
cin>>a;
cout<<"Enter any number2"<<endl;
cin>>b;
if(a%b==0 or b%a==0){
cout<<"second number is multiple of first number"<<endl;
}
}
Output;
Algorithm;
Program 4;
#include <iostream>
using namespace std;
int main(){
int a;
cout<<"Enter you marks :";
cin>>a;
if(a>=90){
cout<<"A grade:";
}
if(a<90&&a>=80){
cout<<"B grade:";
}
if(a<80&&a>=70){
cout<<"C grade:";
}
if(a<70 && a>=60){
cout<<"D grade:";
}
if(a<60){
cout<<"F grade:";
}
Output;
Algorithm;
Input a (integer): // Get the input marks.
If a >= 90:
Output: "A grade"
Else, if 80 <= a < 90:
Output: "B grade"
Else:
Output: "F grade"
Program 5;
#include <iostream>
int main()
{
int a,b,c;
cout<<"Enter a"<<endl;
cin>>a;
cout<<"Enter b"<<endl;
cin>>b;
cout<<"Enter c"<<endl;
cin>>c;
if(a>b and a>c){
cout<<"a is greatest";
}
else if(b>a and b>c){
cout<<"b is greatest";
}
else{
cout<<"c is greatest";
}
}
Output;
Algorithm;
Prompt the user to enter three integers a, b, and c.
Read the values of a, b, and c from the user.
Use conditional statements (if and else if) to compare the values of a, b, and c
to determine the greatest among them.
Display the result indicating which variable is the greatest.
Program 6;
#include <iostream>
int main(){
int a,b,c, avg ,sum;
cout<<"Enter your marks 1:";
cin>>a;
cout<<"Enter your marks 2:";
cin>>b;
cout<<"Enter your marks 3:";
cin>>c;
sum =a+b+c;
cout<<"your sum is:"<<sum<<endl;
avg=sum/3;
cout<<"Your average is :"<<avg;
}
Output;
Algorithm;
Start
Declare variables: a, b, c, avg, sum
Display "Enter your marks 1:"
Read input for 'a'
Display "Enter your marks 2:"
Read input for 'b'
Display "Enter your marks 3:"
Read input for 'c'
Calculate sum = a + b + c
Display "Your sum is:" followed by the value of 'sum'
Calculate avg = sum / 3
Display "Your average is:" followed by the value of 'avg'
End
Program 7;
#include<iostream>
int main(){
int salary,salary1,salary2,grade,bonus;
cout<<"Enter your salery :";
cin>>salary;
cout<<"Enter also grade:";
cin>>grade;
if(grade>15){
bonus=salary*50/100;
salary1=salary+bonus;
cout<<"Salary ater 50 % bonus is :"<<salary1;
}
else if (grade<=15){
bonus = salary*25/100;
salary2=salary+bonus;
cout<<"Salary after 25 % bonus is :"<<salary2;
}
else {
cout<<"The total salary is:"<<salary;
}
Output;
Algorithm;
Get the input for salary (employee salary) from the user.
Get the input for grade (employee grade) from the user.
Check if grade is greater than 15.
If true, calculate a 50% bonus on salary.
Set bonus to salary * 50 / 100.
Set salary1 to salary + bonus.
Display "Salary after 50% bonus is: salary1".
If false, check if grade is less than or equal to 15.
If true, calculate a 25% bonus on salary.
Set bonus to salary * 25 / 100.
Set salary2 to salary + bonus.
Display "Salary after 25% bonus is: salary2".
If both conditions are false, display "The total salary is: salary".
Display the calculated salary or the original salary based on the conditions.
Program 8;
#include <iostream>
else if(n3>n2&&n3>n1&&n3>n4&&n3>n5){
cout<<"n3 greatest and n1 n2 n5 n4 are small:";
}
else if(n4>n2&&n4>n3&&n4>n1&&n4>n5){
cout<<"n4 greatest and n1 n2 n3 n5 are small:";
}
else if(n5>n1&&n5>n2&&n5>n3&&n5>n4){
cout<<"N5 is greatest and n1 n2 n3 n4 are small:";
}
Output;
Algorithm;
Initialize variables n1, n2, n3, n4, n5 to store the input numbers.
Prompt the user to enter num1 and store the input in n1.
Prompt the user to enter num2 and store the input in n2.
Prompt the user to enter num3 and store the input in n3.
Prompt the user to enter num4 and store the input in n4.
Prompt the user to enter num5 and store the input in n5.
Check the following conditions to find the greatest number:
a. If n1 is greater than n2, n3, n4, and n5, then output "n1 is greatest and n5, n2, n3, n4 are small."
b. Else if n2 is greater than n1, n3, n4, and n5, then output "n2 is greatest and n1, n5, n3, n4 are small."
c. Else if n3 is greater than n1, n2, n4, and n5, then output "n3 is greatest and n1, n2, n5, n4 are small."
d. Else if n4 is greater than n1, n2, n3, and n5, then output "n4 is greatest and n1, n2, n3, n5 are small."
e. Else if n5 is greater than n1, n2, n3, and n4, then output "n5 is greatest and n1, n2, n3, n4 are small."