Sie sind auf Seite 1von 8

Name:Haroon Umer Abdullah

Department: Mechanical Engineering


Syndicate:A CMS ID: auabdullah.me41ceme

Submitted to : Sir M.Ismail


Task no.1:
Code:
#include<iostream>
#include<conio.h>

using namespace std;

int main(){

int a=0, b=0, c=0, d=0;


cout<<"Enter number a ="; //Prompt the user to enter the value of first number
cin>>a;

cout<<"Enter number b ="; //Prompt the user to enter the value of second number
cin>>b;

cout<<endl<<"Value of a ="<< a <<endl;


cout<<"Value of b ="<< b <<endl;

c=a;
d=b;

if(c==a && d==b){


a=d;
b=c;

} //Logic applied for swapping

cout<<endl<<"Swapped Value of a = "<< a <<endl ; //Swapped value of "a"


cout<<"Swapped Value of b = "<< b <<endl ; //Swapped value of "b"

_getch();

return 0;
}
Output (1):

Task no. 2:
Code:
#include<iostream>
#include<conio.h>

using namespace std;

int main(){

int a=0, b=0, c=0, d=0;


cout<<"Enter a 3-digit number ="; //Prompt the user to enter a 3-digit number
cin>>a;

b=a%10 + (a/10)/10 + (a/10)%10;

cout<<"sum of digits = "<< b ; //Sum of digits

_getch();

return 0;
}
Output (2):

Task no. 3:
Code:
#include<iostream>
#include<conio.h>

using namespace std;

int main(){

int a=0;

cout<<"Enter Marks (out of 100) = "; //Prompt the user to enter the grade
cin>>a;

cout<<"Your grade is ";

if(a > 80){


cout<<"A";
} //For grade A
if(a>=71 && a<=80){
cout<<"B";
} //For grade B
if(a>60 && a<=71){
cout<<"C";
} //For grade C
if(a<=60){
cout<<"F";
} //For grade F

_getch();

return 0;
}

Output (3):
Task no. 4:
Code:
#include<iostream>
#include<conio.h>

using namespace std;

int main() {
char cha;
cout << "Enter any letter : ";
cin >> cha; //Prompt the user to enter the character
cout << endl;

if (cha >= 65 && cha <= 90) {


cout << "The Entered letter is in Upper case \n";
cha = cha + 32;
cout << "Its lower case letter is :" << cha << endl;
} //Logic to convert Upper case to lower case
else {
cout << "The Entered letter is in Lower Case \n";
cha = cha - 32;
cout << "Its Upper case is : " << cha;
} //Logic to convert lower case to upper case
_getch();
return 0;
}
Output (4):
Task no. 5:
Code:
#include<iostream>
#include<conio.h>

using namespace std;

int main(){

int runs=0, balls=0, match=1, r=0, b=0;


double strike=0;

while(match<=5){
cout<<"Match no. "<<match<<endl;

cout<<"Enter the runs scored : ";


cin>>runs; //Prompt the user to enter the number of runs
r= r + runs;

cout<<"Enter the number of balls faced : ";


cin>>balls; //Prompt the user to enter the number of balls
b= b + balls;

strike=static_cast<double> (runs)/balls; //Conversion of integer value to floating point

cout<<"individual strike rate for match no."<<match<<" is : "<< strike


<<endl; //individual strike rate for respective match

match= match + 1;
cout<<endl<<"--------------------------------------------------------------
"<<endl;
}

r=r/5;
cout<<"Average for these 5 matches : "<<r<<endl;

_getch();

return 0;
}
Output (5):

Das könnte Ihnen auch gefallen