Name : Sybt-e-anwar Qais
Class : MAT-06
Reg no. : 130301017
ASSIGNMENT 2
Problem 1
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x;
x=0;
while (x<5)
{cout<<"I LOVE PAKISTAN"<<'\n';
x++;}
cout<<'\n'<<'\n'<<" THE END";
getch();
}
Print screen:
Problem 2
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x, n;
x=0;
n=1;
while (n<10)
{
x=x+n;
cout<<"The odd numbers are : "<<n<<endl;
n=n+2;
}
cout<<'\n'<<'\n'<<" THE SUM IS : "<<x;
getch();
}
Print screen:
Problem 3
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x,z,a;
a=0;
cout<<"Enter the number whose table is required"<<'\n'<<'\n';
cin>>z;
while(a<11)
{
x=z*a;
cout<<'\n'<<z<<" * "<<a<<" = "<<x<<endl;
a++;
}
getch();
Print screen:
Problem 4
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x,A; // 'x' is the integer,,,,whereas 'A' is the answer;
cout<<"Enter the integar greater than ZERO"<<'\n'<<endl;
cin>>x;
cout<<'\n'<<'\n'<<"The equivalent binary number of the required integar is : ";
while(x>0)
{
A=x%2;
x=x/2;
cout<<A;
}
getch();
}
Print screen:
Problem 5
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
long int F,x; // 'F' is factorial,,,,,'x' is the input integar;
cout<<"Enter any integar value"<<'\n'<<endl;
cin>>x;
F=1;
while(x>0)
{
F= F*x;
x=x-1;
}
cout<<'\n'<<"The factorial of the required no is : "<<F<<endl;
getch();
}
Print screen:
Problem 6
Coding;
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
float x,z;
x=0.0;
z=1.0;
while(z<=45)
{
x=x+1/z;
z++;
cout<<"The sum of the gven series is : "<<x<<endl;
getch();
}
Print screen:
Problem 7
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x;
x=10;
while(x>0)
{
cout<<x--<<" ";
}
getch();
}
Print screen:
Problem 8
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x;
x=1;
do
{
cout<<x<<" ";
x++;
}
while(x<=10);
getch();
}
Print screen:
Problem 9
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
char Name[50];
char Op;
int Marks;
Start:
cout<<'\n'<<"Enter the Name if the student"<<'\n'<<'\n';
cin>>Name;
cout<<'\n'<<"Enter the Marks of the student"<<'\n'<<'\n';
cin>>Marks;
cout<<'\n'<<"The record of the student is : "<<'\n'<<'\n';
cout<<'\n'<<"Name"<<'\t'<<'\t'<<"Marks"<<endl;
cout<<'\n'<<Name<<'\t'<<'\t'<<Marks<<endl<<'\n'<<'\n';
cout<<'\n'<<"Do you want any more record?? Y/N ?"<<'\n'<<'\n';
cin>>Op;
if(Op=='Y')
{goto Start;}
else
{goto End;}
End:
cout<<'\n'<<'\n'<<"THE END";
getch();
}
Print screen:
Problem 10
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x,y;
cout<<"Enter any integar"<<'\n'<<'\n';
cin>>x;
do
{
y=x%8;
cout<<'\n'<<'\n'<<y;
x=x/8;
}
while(x>0);
{cout<<'\n'<<'\n'<<"The End";}
getch();
}
Print screen:
Question 11
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int F,a;
cout<<"Enter any number"<<'\n'<<'\n';
cin>>a;
F=1;
do
{
F=F*a;
a--;
}
while(a>0);
{
cout<<'\n'<<'\n'<<F;
}
getch();
}
Print screen:
Question 12
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
char Name[50],op;
int marks,x;
Begin:
x=1;
for(x=1;x<=1;x++)
{
cout<<'\n'<<"Enter the name "<<'\n'<<'\n';
cin>>Name;
cout<<'\n'<<"Enter the marks"<<'\n'<<'\n';
cin>>marks;
cout<<'\n'<<"Name : "<<Name<<'\n'<<'\n'<<"Marks : "<<marks<<'\n'<<'\n';
}
cout<<'\n'<<"Do you want to back ? Y/N "<<'\n'<<'\n';
cin>>op;
if(op=='Y')
goto Begin;
else if (op=='N')
goto End;
End:
cout<<'\n'<<"THE END";
getch();
Print screen:
Question 13
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x;
cout<<'\n'<<"The First Ten Natural Numbers Are : "<<'\n'<<'\n';
x=1;
for(x=1;x<=10;x++)
{
cout<<x<<" ";
}
cout<<'\n'<<'\n'<<"THE END";
getch();
}
Print screen:
Question 14
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x,A,z;
cout<<'\n'<<'\n'<<"Enter the integar whose table is required : "<<'\n'<<'\n';
cin>>x;
cout<<'\n';
for(z=1;z<=10;z++)
{
A=x*z;
cout<<x<<" * "<<z<<" = "<<A<<endl;
}
cout<<'\n'<<'\n'<<"THE END";
getch();
}
Print screen:
Question 15
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int x,A,z;
A=0;
for(x=1;x<=10;x+=2)
{
A=A+x;
cout<<" "<<x;
}
cout<<'\n'<<'\n'<<"The sum of these numbers is : "<<A;
cout<<'\n'<<'\n'<<"THE END";
getch();
Print screen:
Question 16
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int a,b;
for(a=1,b=10;a<=10;a++,b--)
{
cout<<" "<<a<<'\t'<<b<<'\n';
cout<<'\n'<<'\n'<<"THE END";
getch();
Print screen:
Question 17
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int a,F;
cout<<"Enter any number "<<'\n'<<'\n';
cin>>a;
F=1;
for(;a>0;a--)
{
F=F*a;
}
cout<<'\n'<<'\n'<<F;
getch();
}
Print screen:
Question 18
FOR
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int c;
for(c=1;c<=5;c++)
cout<<"I LOVE PAKISTAN"<<'\n';
getch();
}
Print screen:
WHILE
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int c;
c=1;
while(c<=5)
{
cout<<"I LOVE PAKISTAN"<<'\n';
c++;
}
getch();
}
Print screen:
DO-WHILE
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int c;
c=1;
do
{
cout<<"I LOVE PAKISTAN"<<'\n';
c++;
}
while(c<=5);
getch();
}
Print screen:
Question 19
Coding;
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int i,j,x;
i=1;
while(i<=3)
{
j=1;
x=1;
while(j<=5)
{
cout<<x<<" ";
x=x+i;
j++;
}
cout<<'\n'<<'\n';
i++;
}
getch();
}
Print screen:
Question 20
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int i,j;
i=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
cout<<j<<" ";
cout<<endl;
}
getch();
}
Print screen:
Question 21
Coding:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int i,j;
i=1;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
cout<<" * ";
cout<<endl;
}
getch();
}
Print screen:
Question 22
Coding:
I wasn’t able to do it Sir, because I couldn’t understand the
procedure.