Assignment 3 F22-8757 Noor-E-Adan
Assignment 3 F22-8757 Noor-E-Adan
Assignment 3 F22-8757 Noor-E-Adan
F22-8757_Noor-e-adan
Question number 1
Solution
----------------------- by while loop -----------------------------------
#include<iostream>
int main()
int num1,num2,i=0,result;
char oper;
Assignment number 3
F22-8757_Noor-e-adan
while (oper!=’q’)
cin>>num1;
cin>>num2;
cout<<"enter the any operator that you want for result and for stop enter q"<<endl;
cin>>oper;
if(oper=='+')
result=num1+num2;
else if(oper=='-')
result = num1-num2;
else if(oper=='*')
result= num1*num2;
else if(oper=='/')
result=num1/num2;
else if(oper=='q')
break ;
}
Assignment number 3
F22-8757_Noor-e-adan
}
return 0;
#include<iostream>
int main()
int num1,num2,i,result;
char oper;
for (i=0;oper!=’q’;i++)
cin>>num1;
cin>>num2;
cout<<"enter the any operator that you want for result and for stop enter q"<<endl;
Assignment number 3
F22-8757_Noor-e-adan
cin>>oper;
if(oper=='+')
result=num1+num2;
else if(oper=='-')
result = num1-num2;
else if(oper=='*')
result= num1*num2;
else if(oper=='/')
result=num1/num2;
else if(oper=='q')
break ;
return 0;
#include<iostream>
int main()
int num1,num2,i,result;
char oper;
do
cin>>num1;
cin>>num2;
cout<<"enter the any operator that you want for result and for stop enter q"<<endl;
cin>>oper;
if(oper=='+')
{
Assignment number 3
F22-8757_Noor-e-adan
result=num1+num2;
else if(oper=='-')
result = num1-num2;
else if(oper=='*')
result= num1*num2;
else if(oper=='/')
result=num1/num2;
else if(oper=='q')
break ;
i++;
while(oper!='q');
return 0;
Question number 2
Solution
Assignment number 3
F22-8757_Noor-e-adan
#include<iostream>
int main()
{ int i=1,num,count=0,j,result,num1,k,counter=0,num2,result2;
cin>>num;
j=2;
while(j<i)
if(i%j==0)
{ count++;
break;
j++;
if(num==9)
{result=i-2;
result2=i-result;
if(result2+result==num)
{
Assignment number 3
F22-8757_Noor-e-adan
cout<<"the sum is"<<ends<<result<<ends<<"and"<<ends<<result2<<endl;
}}
if(count==0&&i!=1)
if(num==5||num==7)
{result=i-2;
result2=i-result;
if(result2+result==num)
num1=num-i;
if(num1+i==num)
if(num1%2!=0 &&num1%3!=0&&num1%5!=0&&num1%7!=0&&num1%9!=0)
count=0;
i++;
Assignment number 3
F22-8757_Noor-e-adan
}
return 0;
#include<iostream>
using namespace std;
int main()
{ int i,num,count=0,j,result,num1,k,counter=0,num2,result2;
cout<<"enter any number"<<endl;
cin>>num;
for( i=1;i <= num;i++) {
for(j=2;j<i;j++)
{
if(i%j==0)
{ count++;
break;
}
j++;
Assignment number 3
F22-8757_Noor-e-adan
}
if(num==9)
{result=i-2;
result2=i-result;
if(result2+result==num)
{
cout<<"the sum is"<<ends<<result<<ends<<"and"<<ends<<result2<<endl;
}}
if(count==0&&i!=1)
{
if(num==5||num==7)
{result=i-2;
result2=i-result;
if(result2+result==num)
{
cout<<"the sum is"<<ends<<result<<ends<<"and"<<ends<<result2<<endl;}
}
num1=num-i;
if(num1+i==num)
{
if(num1%2!=0 &&num1%3!=0&&num1%5!=0&&num1%7!=0&&num1%9!=0)
{
cout<<"the sum of number is"<<ends<<i<<ends<<"and"<<ends<<num1<<endl;
Assignment number 3
F22-8757_Noor-e-adan
count=0;
return 0;
}
#include<iostream>
int main()
{ int i=1,num,count=0,j,result,num1,k,counter=0,num2,result2;
cin>>num;
do {
do
Assignment number 3
F22-8757_Noor-e-adan
{ j=2;
if(i%j==0)
{ count++;
break;
j++;
}while(j<i);
if(num==9)
{result=i-2;
result2=i-result;
if(result2+result==num)
}}
if(count==0&&i!=1)
if(num==5||num==7)
{result=i-2;
result2=i-result;
if(result2+result==num)
num1=num-i;
if(num1+i==num)
if(num1%2!=0 &&num1%3!=0&&num1%5!=0&&num1%7!=0&&num1%9!=0)
Assignment number 3
F22-8757_Noor-e-adan
count=0;
i++;
}while(i<=num);
return 0;
Question number 3
Solution
#include<iostream>
#include<cmath>
int main()
{int i=1,num;
float x;
cout<<"------------first point----------------"<<endl;
cout<<endl;
cin>>x;
while(x>=0)
cout<<x<<ends<<ends;
x=x-0.5;
cout<<endl;
cout<<"-------------second point-----------------"<<endl;
cout<<endl;
while(i<=50)
Assignment number 3
F22-8757_Noor-e-adan
{ if(i%2!=0)
{cout<<sqrt(i)<<ends<<ends;
i++;
cout<<endl;
cout<<"-------------third point--------------------"<<endl;
cout<<endl;
cin>>num;
i=1;
while(i<=num)
{cout<<"hello world"<<endl;
i++;
cout<<endl;
cout<<"---------------forth point---------------------"<<endl;
cout<<endl;
int num2,num1,oper,result;
cin>>num2;
cin>>num1;
i=1;
while(i<=10000)
cout<<endl;
cout<<endl;
cin>>oper;
switch(oper)
{case 1:
result=num2+num1;
break;
case 2:
result=num2-num1;
break;
case 3:
result=num2*num1;
break;
case 4:
result=num2/num1;
break;
case 5:
result=num2%num1;
break;
case 6:
int j;
j=1;
result=1;
Assignment number 3
F22-8757_Noor-e-adan
while(j<=num1)
{result=result*j;
j++;
break;
case 7:
exit(0);
break;
default:
break;
return 0;
#include<iostream>
#include<cmath>
int main()
{int i=1,num;
float x;
Assignment number 3
F22-8757_Noor-e-adan
cout<<"------------first point----------------"<<endl;
cout<<endl;
cin>>x;
do{
cout<<x<<ends<<ends;
x=x-0.5;
while(x>=0);
cout<<endl;
cout<<"-------------second point-----------------"<<endl;
cout<<endl;
do { if(i%2!=0)
{cout<<sqrt(i)<<ends<<ends;
i++;
}while(i<=50);
cout<<endl;
cout<<"-------------third point--------------------"<<endl;
cout<<endl;
cin>>num;
i=1;
do
{cout<<"hello world"<<endl;
i++;
}while(i<=num);
cout<<endl;
cout<<"---------------forth point---------------------"<<endl;
cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
int num2,num1,oper,result;
cin>>num2;
cin>>num1;
i=1;
do
cout<<endl;
cout<<endl;
cin>>oper;
switch(oper)
{case 1:
result=num2+num1;
break;
case 2:
result=num2-num1;
break;
case 3:
result=num2*num1;
case 4:
result=num2/num1;
break;
case 5:
result=num2%num1;
break;
case 6:
int j;
j=1;
result=1;
do
{result=result*j;
j++;
} while(j<=num1);
break;
case 7:
exit(0);
break;
default:
break;
}while(i<=10000);
return 0;
Assignment number 3
F22-8757_Noor-e-adan
}
#include<iostream>
#include<cmath>
int main()
{int i,num;
float x;
cout<<"------------first point----------------"<<endl;
cout<<endl;
cin>>x;
for(i=1;x>=0;i++)
cout<<x<<ends<<ends;
x=x-0.5;
cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
cout<<"-------------second point-----------------"<<endl;
cout<<endl;
for(i=1;i<=50;i++)
{ if(i%2!=0)
{cout<<sqrt(i)<<ends<<ends;
cout<<endl;
cout<<"-------------third point--------------------"<<endl;
cout<<endl;
cin>>num;
for(i=1;i<=num;i++)
{cout<<"hello world"<<endl;
cout<<endl;
cout<<"---------------forth point---------------------"<<endl;
cout<<endl;
int num2,num1,oper,result;
cin>>num2;
cin>>num1;
for(i=1;i<=10000;i++)
cout<<endl;
cout<<endl;
cin>>oper;
switch(oper)
{case 1:
result=num2+num1;
break;
case 2:
result=num2-num1;
break;
case 3:
result=num2*num1;
break;
case 4:
result=num2/num1;
break;
case 5:
result=num2%num1;
break;
case 6:
Assignment number 3
F22-8757_Noor-e-adan
int j;
result=1;
for(j=1;j<=num1;j++)
{result=result*j;
break;
case 7:
exit(0);
break;
default:
break;
return 0;
Question number 4
Solution
#include<iostream>
#include<cmath>
int main()
{ double result,sum=0;
int i=1,num;
cin>>num;
while(i<=num)
result=1 / pow(i,i);
cout<<"1/"<<i<<"^"<<i<<ends<<"="<<ends<<result<<endl;
sum+=result;
i++;
return 0;
#include<iostream>
#include<cmath>
int main()
{ double result,sum=0;
int i=1,num;
cin>>num;
do
result=1 / pow(i,i);
cout<<"1/"<<i<<"^"<<i<<ends<<"="<<ends<<result<<endl;
sum+=result;
i++;
Assignment number 3
F22-8757_Noor-e-adan
}while(i<=num);
return 0;
#include<iostream>
#include<cmath>
int main()
{ double result,sum=0;
int i,num;
cin>>num;
for(i=1;i<=num;i++)
result=1 / pow(i,i);
cout<<"1/"<<i<<"^"<<i<<ends<<"="<<ends<<result<<endl;
sum+=result;
Assignment number 3
F22-8757_Noor-e-adan
i++;
return 0;
Question number 5
Solution
#include<iostream>
int main()
{ int num,k,result,num1,temp;
cin>>num;
cin>>k;
result=num+k;
num1=num;
cout<<num1<<ends;
Assignment number 3
F22-8757_Noor-e-adan
temp=num;
while(num<=result)
{if(num<=temp+3)
if(num%2==0)
num1= num1/2;
cout<<num1<<ends;
else if(num%2!=0)
num1=3*num1+1;
cout<<num1<<ends;
}}
else if(num==temp+4)
num1=num1/2;
cout<<num1<<ends;}
else if(num==temp+5)
num1=3*num1+1;
cout<<num1<<ends;
else if(num>temp+5&&num<=result)
num1=num1/2;
cout<<num1<<ends;
Assignment number 3
F22-8757_Noor-e-adan
}
num++;
return 0;
}
Assignment number 3
F22-8757_Noor-e-adan
#include<iostream>
int main()
{ int num,k,result,num1,temp;
cin>>num;
cin>>k;
result=num+k;
num1=num;
cout<<num1<<ends;
temp=num;
do {if(num<=temp+3)
if(num%2==0)
num1= num1/2;
cout<<num1<<ends;
else if(num%2!=0)
Assignment number 3
F22-8757_Noor-e-adan
{
num1=3*num1+1;
cout<<num1<<ends;
}}
else if(num==temp+4)
num1=num1/2;
cout<<num1<<ends;}
else if(num==temp+5)
num1=3*num1+1;
cout<<num1<<ends;
else if(num>temp+5&&num<=result)
num1=num1/2;
cout<<num1<<ends;
num++;
}while(num<=result);
return 0;
#include<iostream>
int main()
{ int num,k,result,num1,temp,i;
cin>>num;
cin>>k;
result=num+k;
num1=num;
cout<<num1<<ends;
temp=num;
for(i=1;num<=result;i++) {if(num<=temp+3)
if(num%2==0)
num1= num1/2;
cout<<num1<<ends;
else if(num%2!=0)
Assignment number 3
F22-8757_Noor-e-adan
{
num1=3*num1+1;
cout<<num1<<ends;
}}
else if(num==temp+4)
num1=num1/2;
cout<<num1<<ends;}
else if(num==temp+5)
num1=3*num1+1;
cout<<num1<<ends;
else if(num>temp+5&&num<=result)
num1=num1/2;
cout<<num1<<ends;
num++;
return 0;
Question number 6
Solution
Assignment number 3
F22-8757_Noor-e-adan
#include<iostream>
Assignment number 3
F22-8757_Noor-e-adan
using namespace std;
int main()
int num1,num2,sum=0,temp1,square,i=0;
char ch='A';
cout<<"------------first point--------------"<<endl;
cout<<endl;
cout<<"enter the first number and it should be smaller than last number"<<endl;
cin>>num1;
temp1=num1;
cin>>num2;
cout<<endl;
cout<<"-----------second point------------"<<endl;
while(num1<=num2)
if(num1%2!=0)
cout<<num1<<ends;
num1++;
cout<<endl;
cout<<endl;
cout<<"------------third point-----------"<<endl;
num1=temp1;
while(num1<=num2)
if(num1%2==0)
{
Assignment number 3
F22-8757_Noor-e-adan
sum=sum+num1;
num1++;
num1=temp1;
cout<<endl;
cout<<endl;
cout<<"--------------forth pont-------------"<<endl;
while(num1<=temp1+10)
cout<<num1<<ends<<ends;
square=num1*num1;
cout<<square<<endl;
num1++;
num1=temp1;
cout<<endl;
cout<<endl;
cout<<"--------------fifth point--------------"<<endl;
sum=0;
while(num1<=num2)
if(num1%2!=0)
{square=num1*num1;
sum=sum+square;
}
Assignment number 3
F22-8757_Noor-e-adan
num1++;
cout<<endl;
cout<<"-------------sixth point-----------------"<<endl;
cout<<endl;
while(i<=25)
{ cout<<ch<<ends;
ch++;
i++;
return 0;
#include<iostream>
int main()
int num1,num2,sum=0,temp1,square,i=0;
Assignment number 3
F22-8757_Noor-e-adan
char ch='A';
cout<<"------------first point--------------"<<endl;
cout<<endl;
cout<<"enter the first number and it should be smaller than last number"<<endl;
cin>>num1;
temp1=num1;
cin>>num2;
cout<<endl;
cout<<"-----------second point------------"<<endl;
do
if(num1%2!=0)
cout<<num1<<ends;
num1++;
} while(num1<=num2);
cout<<endl;
cout<<endl;
cout<<"------------third point-----------"<<endl;
num1=temp1;
do{
if(num1%2==0)
sum=sum+num1;
num1++;
}while(num1<=num2);
Assignment number 3
F22-8757_Noor-e-adan
cout<<" the sum of all even number are "<<ends<<ends<<sum<<endl;
num1=temp1;
cout<<endl;
cout<<endl;
cout<<"--------------forth pont-------------"<<endl;
do{
cout<<num1<<ends<<ends;
square=num1*num1;
cout<<square<<endl;
num1++;
}while(num1<=temp1+10);
num1=temp1;
cout<<endl;
cout<<endl;
cout<<"--------------fifth point--------------"<<endl;
sum=0;
do {
if(num1%2!=0)
{square=num1*num1;
sum=sum+square;
num1++;
}while(num1<=num2);
Assignment number 3
F22-8757_Noor-e-adan
cout<<"sum of the square of odd is"<<ends<<sum<<endl;
cout<<endl;
cout<<"-------------sixth point-----------------"<<endl;
cout<<endl;
do{ cout<<ch<<ends;
ch++;
i++;
}while(i<=25);
return 0;
#include<iostream>
int main()
int num1,num2,sum=0,temp1,square,i=0;
Assignment number 3
F22-8757_Noor-e-adan
char ch='A';
cout<<"------------first point--------------"<<endl;
cout<<endl;
cout<<"enter the first number and it should be smaller than last number"<<endl;
cin>>num1;
temp1=num1;
cin>>num2;
cout<<endl;
cout<<"-----------second point------------"<<endl;
for(i=1;num1<=num2;i++)
if(num1%2!=0)
cout<<num1<<ends;
num1++;
cout<<endl;
cout<<endl;
cout<<"------------third point-----------"<<endl;
num1=temp1;
for(i=1;num1<=num2;i++){
if(num1%2==0)
sum=sum+num1;
num1++;
}
Assignment number 3
F22-8757_Noor-e-adan
cout<<" the sum of all even number are "<<ends<<ends<<sum<<endl;
num1=temp1;
cout<<endl;
cout<<endl;
cout<<"--------------forth pont-------------"<<endl;
for(i=1;num1<=temp1+10;i++){
cout<<num1<<ends<<ends;
square=num1*num1;
cout<<square<<endl;
num1++;
num1=temp1;
cout<<endl;
cout<<endl;
cout<<"--------------fifth point--------------"<<endl;
sum=0;
for(i=1;num1<=num2;i++) {
if(num1%2!=0)
{square=num1*num1;
sum=sum+square;
num1++;
}
Assignment number 3
F22-8757_Noor-e-adan
cout<<"sum of the square of odd is"<<ends<<sum<<endl;
cout<<endl;
cout<<"-------------sixth point-----------------"<<endl;
cout<<endl;
for(i=1;i<=25;i++){ cout<<ch<<ends;
ch++;
return 0;
Question number 7
Solution
#include<iostream>
int main()
{ int
i=1,sum,cake,icecream,yougurt,milk,flour,rice,potato,salt,tea,item,num=0,num1=0,num2=0,num3=0,num4=0,num
5=0,num6=0,num7=0,num8=0;
Assignment number 3
F22-8757_Noor-e-adan
while(i<=9)
cin>>item;
if(item==1)
cout<<endl;
cin>>cake;
num=cake*20;
cout<<endl;
if(item==2)
cout<<endl;
cin>>icecream;
num1=icecream*15;
cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
}
if(item==3)
cout<<endl;
cin>>yougurt;
num2=yougurt*25;
cout<<endl;}
if(item==4)
cout<<endl;
cin>>milk;
num3=milk*20;
cout<<endl;}
if(item==5)
cout<<endl;
cin>>flour;
num4=flour*30;
cout<<endl;}
if(item==6)
cout<<endl;
cin>>rice;
num5=rice*10;
Assignment number 3
F22-8757_Noor-e-adan
cout<<"the total price of rice is "<<ends<<num5<<endl;
cout<<endl;}
if(item==7)
cout<<endl;
cin>>potato;
num6=potato*5;
cout<<endl;}
if(item==8)
cout<<endl;
cin>>salt;
num7=salt*5;
cout<<endl;}
if(item==9)
cout<<endl;
cin>>tea;
num8=tea*5;
cout<<endl;}
if(item==10)
{ break;
}
Assignment number 3
F22-8757_Noor-e-adan
i++;
sum=num+num1+num2+num3+num4+num5+num6+num7+num8;
cout<<endl;
if(sum>200)
cout<<endl;
else if(sum<200)
{ sum=sum*10;
cout<<"the total amount by adding shipping and handling amount are "<<ends<<sum<<endl;
cout<<endl;
return 0;
#include<iostream>
int main()
{ int
i=1,sum,cake,icecream,yougurt,milk,flour,rice,potato,salt,tea,item,num=0,num1=0,num2=0,num3=0,num4=0,num
5=0,num6=0,num7=0,num8=0;
do
cin>>item;
if(item==1)
cout<<endl;
cin>>cake;
num=cake*20;
cout<<endl;
if(item==2)
cout<<endl;
cin>>icecream;
num1=icecream*15;
cout<<endl;
if(item==3)
cout<<endl;
cin>>yougurt;
num2=yougurt*25;
Assignment number 3
F22-8757_Noor-e-adan
cout<<"the total price of yougurt is "<<ends<<num2<<endl;
cout<<endl;}
if(item==4)
cout<<endl;
cin>>milk;
num3=milk*20;
cout<<endl;}
if(item==5)
cout<<endl;
cin>>flour;
num4=flour*30;
cout<<endl;}
if(item==6)
cout<<endl;
cin>>rice;
num5=rice*10;
cout<<endl;}
if(item==7)
cout<<endl;
cin>>potato;
Assignment number 3
F22-8757_Noor-e-adan
num6=potato*5;
cout<<endl;}
if(item==8)
cout<<endl;
cin>>salt;
num7=salt*5;
cout<<endl;}
if(item==9)
cout<<endl;
cin>>tea;
num8=tea*5;
cout<<endl;}
if(item==10)
{ break;
i++;
}while(i<=9);
sum=num+num1+num2+num3+num4+num5+num6+num7+num8;
cout<<endl;
if(sum>200)
else if(sum<200)
{ sum=sum*10;
cout<<"the total amount by adding shipping and handling amount are "<<ends<<sum<<endl;
cout<<endl;
return 0;
#include<iostream>
int main()
Assignment number 3
F22-8757_Noor-e-adan
{ int
i,sum,cake,icecream,yougurt,milk,flour,rice,potato,salt,tea,item,num=0,num1=0,num2=0,num3=0,num4=0,num5=
0,num6=0,num7=0,num8=0;
for(i=1;i<=9;i++)
cin>>item;
if(item==1)
cout<<endl;
cin>>cake;
num=cake*20;
cout<<endl;
if(item==2)
cout<<endl;
cin>>icecream;
Assignment number 3
F22-8757_Noor-e-adan
num1=icecream*15;
cout<<endl;
if(item==3)
cout<<endl;
cin>>yougurt;
num2=yougurt*25;
cout<<endl;}
if(item==4)
cout<<endl;
cin>>milk;
num3=milk*20;
cout<<endl;}
if(item==5)
cout<<endl;
cin>>flour;
num4=flour*30;
cout<<endl;}
if(item==6)
cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
cout<<"enter the number of rice that you want"<<endl;
cin>>rice;
num5=rice*10;
cout<<endl;}
if(item==7)
cout<<endl;
cin>>potato;
num6=potato*5;
cout<<endl;}
if(item==8)
cout<<endl;
cin>>salt;
num7=salt*5;
cout<<endl;}
if(item==9)
cout<<endl;
cin>>tea;
num8=tea*5;
cout<<endl;}
Assignment number 3
F22-8757_Noor-e-adan
if(item==10)
{ break;
sum=num+num1+num2+num3+num4+num5+num6+num7+num8;
cout<<endl;
if(sum>200)
cout<<endl;
else if(sum<200)
{ sum=sum*10;
cout<<"the total amount by adding shipping and handling amount are "<<ends<<sum<<endl;
cout<<endl;
return 0;
Question number 8
Solution
#include<iostream>
int main()
{ int i=1,subject,count=0,count1=0,count2=0,count3=0,count4=0,count5=0;
char grade;
cin>>subject;
while(i<=subject)
cin>>grade;
if(grade=='a'||grade=='A')
{ count++;
if(grade=='b'||grade=='B')
{ count1++;
if(grade=='c'||grade=='C')
{ count2++;
Assignment number 3
F22-8757_Noor-e-adan
}
if(grade=='d'||grade=='D')
{ count3++;
if(grade=='e'||grade=='E')
{ count4++;
if(grade=='f'||grade=='F')
{ count5++;
i++;
cout<<endl;
cout<<"A :"<<ends<<count<<endl;
cout<<"B :"<<ends<<count1<<endl;
cout<<"C :"<<ends<<count2<<endl;
cout<<"D :"<<ends<<count3<<endl;
cout<<"E :"<<ends<<count4<<endl;
cout<<"F :"<<ends<<count5<<endl;
return 0;
#include<iostream>
int main()
{ int i=1,subject,count=0,count1=0,count2=0,count3=0,count4=0,count5=0;
char grade;
cin>>subject;
do
cin>>grade;
if(grade=='a'||grade=='A')
{ count++;
if(grade=='b'||grade=='B')
{ count1++;
if(grade=='c'||grade=='C')
{ count2++;
Assignment number 3
F22-8757_Noor-e-adan
}
if(grade=='d'||grade=='D')
{ count3++;
if(grade=='e'||grade=='E')
{ count4++;
if(grade=='f'||grade=='F')
{ count5++;
i++;
}while(i<=subject);
cout<<endl;
cout<<"A :"<<ends<<count<<endl;
cout<<"B :"<<ends<<count1<<endl;
cout<<"C :"<<ends<<count2<<endl;
cout<<"D :"<<ends<<count3<<endl;
cout<<"E :"<<ends<<count4<<endl;
cout<<"F :"<<ends<<count5<<endl;
return 0;
#include<iostream>
int main()
{ int i,subject,count=0,count1=0,count2=0,count3=0,count4=0,count5=0;
char grade;
cin>>subject;
for(i=1;i<=subject;i++)
cin>>grade;
if(grade=='a'||grade=='A')
{ count++;
if(grade=='b'||grade=='B')
{ count1++;
if(grade=='c'||grade=='C')
{ count2++;
Assignment number 3
F22-8757_Noor-e-adan
}
if(grade=='d'||grade=='D')
{ count3++;
if(grade=='e'||grade=='E')
{ count4++;
if(grade=='f'||grade=='F')
{ count5++;
cout<<endl;
cout<<"A :"<<ends<<count<<endl;
cout<<"B :"<<ends<<count1<<endl;
cout<<"C :"<<ends<<count2<<endl;
cout<<"D :"<<ends<<count3<<endl;
cout<<"E :"<<ends<<count4<<endl;
cout<<"F :"<<ends<<count5<<endl;
return 0;
Question number 9
Solution
#include<iostream>
int main()
int reminder,i=0,num;
cin>>num;
cout<<endl;
if(num==0||num==1)
{cout<<num;
else
while(num!=0)
reminder=num%2;
num/=2;
cout<<reminder;
}}
cout<< endl;
return 0;
Assignment number 3
F22-8757_Noor-e-adan
}
#include<iostream>
int main()
int reminder,i=0,num;
cin>>num;
cout<<endl;
if(num==0||num==1)
{cout<<num;
else
do
reminder=num%2;
num/=2;
cout<<reminder;
}while(num!=0);}
cout<< endl;
Assignment number 3
F22-8757_Noor-e-adan
return 0;
#include<iostream>
int main()
int reminder,i,num;
cin>>num;
cout<<endl;
if(num==0||num==1)
{cout<<num;
else
for(i=0;num!=0;i++)
reminder=num%2;
Assignment number 3
F22-8757_Noor-e-adan
num/=2;
cout<<reminder;
}}
cout<< endl;
return 0;
Question number 10
Solution
#include<iostream>
int main()
int i=1,j,k,size;
char ch;
cin>>size;
cin>>ch;
Assignment number 3
F22-8757_Noor-e-adan
switch(ch)
case '1':
i=1;
while(i<=size)
{ j=1;
while(j<=size)
{cout<<i;
j++;
cout<<endl;
i++;}}
break;
case '2':
i=1;
while(i<=size)
{ j=1;
while(j<=size)
cout<<j;
j++;
}cout<<endl;
i++;
} break;
case '3':
i=size;
while(i>=1)
{ j=1;
while(j<=size)
Assignment number 3
F22-8757_Noor-e-adan
{
cout<<i;
j++;
}cout<<endl;
i--;;
break;
case '4':
i=1;
while(i<=size)
{ j=size;
while(j>=1)
cout<<j;
j--;
}cout<<endl;
i++;
} break;
default:
break;
cout<<endl;
return 0;
#include<iostream>
int main()
int i=1,j,k,size;
char ch;
cin>>size;
cin>>ch;
switch(ch)
case '1':
i=1;
do
{ j=1;
{cout<<i;
j++;
}while(j<=size);
cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
i++;}while(i<=size);}
break;
case '2':
i=1;
do
{ j=1;
do
cout<<j;
j++;
} while(j<=size);
cout<<endl;
i++;
} while(i<=size);break;
case '3':
i=size;
do
{ j=1;
do
cout<<i;
j++;
}while(j<=size);cout<<endl;
i--;;
} while(i>=1);
break;
case '4':
i=1;
do
{ j=size;
Assignment number 3
F22-8757_Noor-e-adan
do
cout<<j;
j--;
}while(j>=1);cout<<endl;
i++;
} while(i<=size);break;
default:
break;
}while(i<=size);
cout<<endl;
return 0;
#include<iostream>
int main()
Assignment number 3
F22-8757_Noor-e-adan
{
int i=1,j,k,size;
char ch;
cin>>size;
cin>>ch;
switch(ch)
case '1':
for(i=1;i<=size;i++)
for(j=1;j<=size;j++)
{cout<<i;
cout<<endl;
}}
break;
case '2':
for(i=1;i<=size;i++)
for(j=1;j<=size;j++)
cout<<j;
Assignment number 3
F22-8757_Noor-e-adan
}
cout<<endl;
} break;
case '3':
for(i=size;i>=1;i--)
for(j=1;j<=size;j++)
cout<<i;
}cout<<endl;
break;
case '4':
for(i=1;i<=size;i++)
for(j=size;j>=1;j--)
cout<<j;
}cout<<endl;
} break;
default:
break;
Assignment number 3
F22-8757_Noor-e-adan
cout<<endl;
return 0;
Question number 11
Solution
#include<iostream>
int main()
{int i=1,j,k,size;
cin>>size;
while(i<=size)
{k=size;
while(k>=i)
{cout<<" ";
k--;
j=2;
while(j<=2*i)
{cout<<"*";
j++;
cout<<endl;
i++;
Assignment number 3
F22-8757_Noor-e-adan
}
i=1;
while(i<=size)
{k=1;
while(k<=i+1)
{cout<<" ";
k++;
j=size*2;
while(j>=2*i+2)
{cout<<"*";
j--;
cout<<endl;
i++;
int main()
{int i=1,j,k,size;
cin>>size;
do
{k=size;
do
{cout<<" ";
k--;
}while(k>=i);
j=2;
do
{cout<<"*";
j++;
}while(j<=2*i);
cout<<endl;
i++;
}while(i<=size);
i=1;
do
{k=1;
do
{cout<<" ";
k++;
}while(k<=i+1);
j=size*2;
do
{cout<<"*";
j--;
Assignment number 3
F22-8757_Noor-e-adan
}while(j>=2*i+2);
cout<<endl;
i++;
}while(i<size);
#include<iostream>
int main()
{int i,j,k,size;
cin>>size;
for(i=1;i<=size;i++)
{k=size;
for(k=size;k>=i;k--)
{cout<<" ";
for(j=2;j<=2*i;j++)
Assignment number 3
F22-8757_Noor-e-adan
{cout<<"*";
cout<<endl;
for(i=1;i<size;i++)
for(k=1;k<=i+1;k++)
{cout<<" ";
j=size*2;
for (j=size*2;j>=2*i+2;j--)
{cout<<"*";
cout<<endl;
Question number 12
Solution
#include<iostream>
int main()
int n=0,count=0,draw=0;
char card;
n++;
draw++;
if (card == 'A'||card=='a')
ace = true;
n = 0;
}
Assignment number 3
F22-8757_Noor-e-adan
else if (n == 1)
check = true;
else if (card == 'j' || card == 'k' || card == 'q' || card == 'Q' || card == 'J' || card == 'K')
count = count + 5;
else
check == true;
cout<<endl;
cout << "the total score you get are: " << ends << count << endl;
return 0;
}
Assignment number 3
F22-8757_Noor-e-adan
#include<iostream>
int main()
int n=0,count=0,draw=0;
char card;
do
n++;
draw++;
if (card == 'A'||card=='a')
ace = true;
Assignment number 3
F22-8757_Noor-e-adan
n = 0;
else if (n == 1)
check = true;
else if (card == 'j' || card == 'k' || card == 'q' || card == 'Q' || card == 'J' || card == 'K')
count = count + 5;
else
check == true;
cout<<endl;
cout << "the total score you get are: " << ends << count << endl;
Assignment number 3
F22-8757_Noor-e-adan
return 0;
#include<iostream>
int main()
int n=0,count=0,draw=0,i;
char card;
for(i=0;check == false;i++)
n++;
draw++;
if (card == 'A'||card=='a')
n = 0;
else if (n == 1)
check = true;
else if (card == 'j' || card == 'k' || card == 'q' || card == 'Q' || card == 'J' || card == 'K')
count = count + 5;
else
check == true;
cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
cout << "the total score you get are: " << ends << count << endl;
return 0;
Question number 13
Solution
Assignment number 3
F22-8757_Noor-e-adan
#include<iostream>
#include<cstdlib>
#include<ctime>
int main()
int turn1,turn2,turn3,turn4,sum1,add1=0,sum2,add2=0,i=1,count1=0,count2=0;
cout<<endl;
cout<<endl;
srand(time(0));
Assignment number 3
F22-8757_Noor-e-adan
while(i<=5)
while(check==false)
turn1=10+(rand()%29);
turn2=10+(rand()%29);
cout<<endl;
sum1=turn1+turn2;
add1=add1+sum1;
turn3=10+(rand()%29);
turn4=10+(rand()%29);
cout<<endl;
sum2=turn3+turn4;
add2=add2+sum2;
cout<<endl;
if(sum1>=50&&sum2!=50)
check = true;
else if(sum2>=50&&sum1!=50)
Assignment number 3
F22-8757_Noor-e-adan
{
check = true;
else if(sum2>=50&&sum1>=50&&sum1==sum2)
else if(sum1>sum2)
{count1++;
else if(sum1<sum2)
{count2++;
} i++;
if(count1>count2)
else if(count1<count2)
else if(count1==count2)
{if(add1>add2)
else if(add1<add2)
Assignment number 3
F22-8757_Noor-e-adan
{cout<<"--------^-^second player is the winner of the match^-^---------------"<<endl;
else if(add1==add2)
cout<<"-------------------^-^match is tie^-^----------------------------"<<endl;
cout<<endl;
return 0;
#include<cstdlib>
#include<ctime>
int main()
int turn1,turn2,turn3,turn4,sum1,add1=0,sum2,add2=0,i=1,count1=0,count2=0;
cout<<endl;
cout<<endl;
srand(time(0));
do
do
turn1=10+(rand()%29);
turn2=10+(rand()%29);
cout<<endl;
sum1=turn1+turn2;
add1=add1+sum1;
turn3=10+(rand()%29);
turn4=10+(rand()%29);
cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
sum2=turn3+turn4;
add2=add2+sum2;
cout<<endl;
if(sum1>=50&&sum2!=50)
check=true;
else if(sum2>=50&&sum1!=50)
check=true;
else if(sum2>=50&&sum1>=50&&sum1==sum2)
else if(sum1>sum2)
{count1++;
else if(sum1<sum2)
{count2++;
} while(check==false);
i++;
Assignment number 3
F22-8757_Noor-e-adan
}while(i<=5);
if(count1>count2)
else if(count1<count2)
else if(count1==count2)
{if(add1>add2)
else if(add1<add2)
else if(add1==add2)
cout<<"-------------------^-^match is tie^-^----------------------------"<<endl;
cout<<endl;
return 0;
#include<iostream>
#include<cstdlib>
#include<ctime>
int main()
int turn1,turn2,turn3,turn4,sum1,add1=0,sum2,add2=0,i,count1=0,count2=0;
cout<<endl;
cout<<endl;
srand(time(0));
for(i=1;i<=5;i++)
for(i=1;check==false;i++)
{
Assignment number 3
F22-8757_Noor-e-adan
cout<<"the first players spin"<<endl;
turn1=10+(rand()%29);
turn2=10+(rand()%29);
cout<<endl;
sum1=turn1+turn2;
add1=add1+sum1;
turn3=10+(rand()%29);
turn4=10+(rand()%29);
cout<<endl;
sum2=turn3+turn4;
add2=add2+sum2;
cout<<endl;
if(sum1>=50&&sum2!=50)
check=true;
else if(sum2>=50&&sum1!=50)
check=true;
}
Assignment number 3
F22-8757_Noor-e-adan
else if(sum2>=50&&sum1>=50&&sum1==sum2)
else if(sum1>sum2)
{count1++;
else if(sum1<sum2)
{count2++;
if(count1>count2)
else if(count1<count2)
else if(count1==count2)
{if(add1>add2)
else if(add1<add2)
else if(add1==add2)
{
Assignment number 3
F22-8757_Noor-e-adan
cout<<"-------------------^-^match is tie^-^----------------------------"<<endl;
cout<<endl;
return 0;