Assignment: Name: Nawaf Rasheed Reg#no: 50816 Program: BS (SE)
Assignment: Name: Nawaf Rasheed Reg#no: 50816 Program: BS (SE)
Question: 02:
Answer:
include <stdio.h>
int main(void){
int num;
scanf("%d",&num);
return 0;
include<stdio.h>
#include<conio.h>
void main ()
float m1,m2,m3;
float per;
float total;
clrscr();
scanf("%f", &m1);
scanf("%f", &m2);
scanf("%f", &m3);
total= m1+m2+m3;
per = (total/300)*100;
getch();
include <stdio.h>
int main(void){
int num;
scanf("%d",&num);
return 0;
Question:04:
Answer:
Example
Input
Input cost price: 1000
Output
Profit: 500
#include <stdio.h>
int main()
{
int cp,sp, amt;
return 0;
}
Output
Enter cost price: 1000
Enter selling price: 1500
Profit = 500
Question:05:
Answer:
/*If ages of Ahmed, Khurram are input through the keyboard. Write a programme
to determine the youngest of the two.*/
#include<stdio.h>
int main()
{
int Ahmed,Khurram ;
printf(" Enter the ages of Ahmed :");
scanf("%d",& Ahmed);
Output :
Enter the ages of Ahmed,Khurram :20
30
Question.no:06:
Answer:
#include <iostream>
int main()
{
int score;
cout << "Enter your grade scored in programming class (0-100)" << endl;
cin >> score;
switch (score) {
case 100:
cout << "You got a perfect score!" << endl;
break;
case 0:
cout << "You failed. Really badly." << endl;
break;
default:
if(score>=0 && score<60) {
cout << "Your Grade : F" << endl;
} else if(score>=60 && score<70) {
cout << "Your Grade : D" << endl;
} else if(score>=70 && score<80) {
cout << "Your Grade : C" << endl;
} else if(score>=80 && score<90) {
cout << "Your Grade : B" << endl;
} else if(score>=90 && score<100) {
cout << "Your Grade : A" << endl;
}
}
}
Question:07:
Answer:
include <iostream>
int main()
{
int drink;
cout << "Pick a beverage.\nType 1 for Coke\nType 2 for Pepsi\nType 3 for Sprite\nType 4 for Water\nType 5 for Mountain
Dew\n";
cin >> drink;
switch(drink) {
case 1:
cout << "You chose Coke\n";
break;
case 2:
cout << "You chose Pepsi\n";
break;
case 3:
cout << "You chose Sprite\n";
break;
case 4:
cout << "You chose Water\n";
break;
case 5:
cout << "You chose Mountain Dew\n";
break;
default:
cout << "Error. choice was not valid, here is your money back.";
}
}
if(drink=1) {
cout << "You chose Coke\n";
} else if(drink=2) {
cout << "You chose Pepsi\n";
} else if(drink=3) {
cout << "You chose Sprite\n";
} else if(drink=4) {
cout << "You chose Water\n";
} else if(drink=5) {
cout << "You cose Mountain Dew\n";
} else {
cout << "Error. choice was not valid, here is your money back.";
}
*/
Question.no:08:
Answer:
# include <iostream>
using namespace std;
int main()
{
char op;
float num1, num2;
switch(op)
{
case '+':
cout << num1+num2;
break;
case '-':
cout << num1-num2;
break;
case '*':
cout << num1*num2;
break;
case '/':
cout << num1/num2;
break;
default:
// If the operator is other than +, -, * or /, error message is shown
cout << "Error! operator is not correct";
break;
}
return 0;
}
Output