You are on page 1of 6

Assignment # 02

Name: Sikandar Ali Khan


Subitted To: Sir. Muzammil
Course: Fop

Solution #01
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int n1,n2,n3,n4,min;
cout << "Enter Four integers: ";
cin >> n1 >> n2 >> n3 >> n4;
min=n1;
if (n2 < min) min = n2;
if (n3 < min) min = n3;
if (n4 < min) min = n4;
cout << "Their minimum is " << min << endl;
system("PAUSE");
return 0;
}

Solution # 02
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int n1, n2, n3, median;
cout << "Enter Three integers: ";
cin >> n1 >> n2 >> n3;
median = n1;
if ( (n1 >= n2) && (n1 <= n3) ) median = n1;
if ( (n2 >= n1) && (n2 <= n3) ) median = n2;
if ( (n3 >= n1) && (n3 <= n2) ) median = n3;
cout << "Median = " << median << endl;
system("PAUSE");
return 0;}

Solution # 03
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int n1,n2,n3,max;
cout << "Enter Three integers: ";
cin >> n1 >> n2 >> n3;
max=n1;
max = n2 < max ? max : n2 ;
max = n3 < max ? max : n3 ;
cout << "Their maximum is " << max << endl;
system("PAUSE");
return 0;
}
Solution # 05
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
unsigned int n, number,d;
cout << "Enter Max Range: ";
cin >> number;
for(n=2 ; n<=number ; n++)
{
bool Is_Prime = true;
for (d=2; d <= n/2; d ++)
{
if (n%d == 0)
Is_Prime = false; }
if(Is_Prime == true)
cout << n << " ";
}
cout <<endl;
system("PAUSE"); return 0;
}

Solution # 07
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
unsigned long n, i, number, val, d1, d2, d3, d4, d5;
cout << "Enter Max Range: ";
cin >> number;
for( i=0 ; i<=number ; i++ )
{
n = i;
d1 = n % 10; n = n/10;
d2 = n % 10; n = n/10;
d3 = n % 10; n = n/10;
d4 = n % 10; n = n/10;
d5 = n % 10; n = n/10;
val = (d1*d1*d1) + (d2*d2*d2) + (d3*d3*d3) + (d4*d4*d4) + (d5*d5*d5);
if(i == val)
cout << val << endl;}
cout << endl;
system("PAUSE");
return 0;}

Solution # 06
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
double last_no, sum = 0, current_no = 1;
cout << "Enter a Positive Number: ";
cin >> last_no;
do
{
sum = sum + current_no*current_no;
cout << "+" << current_no*current_no;
current_no++;
}while (current_no <= last_no);
cout << " = " << sum <<endl;
system("PAUSE");
return 0;
}

Solution # 10
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
unsigned long i, j, n=10;
unsigned char ch;
for( i = 0 ; i < n ; i++ )
{
ch='A';
for ( j = 1 ; j <= n-i ; j++ ) cout <<" ";
for ( j = 1 ; j <= i ; j++ ) cout <<" "<<ch++;
cout << endl;
}
n=n-1;
for( i = n ; i > 0 ; i-- )
{
ch='A';
for ( j = 0 ; j <= n-i ; j++ ) cout <<" ";
for ( j = 1 ; j <= i ; j++ ) cout <<" "<<ch++;
cout << endl;}
system ("PAUSE");
return 0;}

You might also like