You are on page 1of 18

COMSATS

UNIVERSITY
ISLAMABAD
NAME: MUHAMMAD USAMA MASOOD
REG.NO: SP20-BCS-033
ASSIGNMENT
SUBMITTED TO : SIR SHAHZAD

PROGRAM 1:

Write a Program that input two numbers and radius of circle from the user.
You give the choice to the user that when user entered # symbol, then it
prints Area and Circumference of circle. If user entered * symbol, then it
displays the Result of Addition and Division of two numbers. You do
perform this task by using “Switch Multiple Selection Statement”

CODE:

#include<iostream>

#include<conio.h>

using namespace std;

int main()

{
float a,b,radius;

char c;

cout<<"enter first number:"<<endl;

cin>>a;

cout<<"enter second number:"<<endl;

cin>>b;

cout<<"enter radius of circle:"<<endl;

cin>>radius;

cout<<"enter choice:"<<endl;

cin>>c;

switch(c)

case'#':

cout<<"area of circle:"<<3.14*(radius*radius)<<endl;

cout<<"circumference of circle:"<<2*3.14*radius<<endl;

break;

case'*':

cout<<"addition of two numbers:"<<a+b<<endl;

cout<<"division of two numbers:"<<a/b<<endl;

default:

cout<<"invalid input..";
}

getch();

return 0;

PROGRAM 2:

Write a Program that input a number for table from the user. And also input
length for table. And shows the table according to its length. You do
perform this task by using “For Loop”

CODE:

#include <iostream>

using namespace std;

int main()

int n, range;

cout << "Enter an integer: ";

cin >> n;

cout << "Enter range: ";


cin >> range;

for (int i = 1; i <= range; ++i) {

cout << n << " * " << i << " = " << n * i << endl;

return 0;

PROGRAM 3:

Write a Program that display the following output on the console ”for
Loop”:- 0 2 4 6 8 . . . . . . . . . . . . . . . . . . . . . . . . 100 1 3 5 7
9 . . . . . . . . . . . . . . . . . . . . . . . . 99

CODE:

#include <iostream>

using namespace std;

int main()

int i;

for(i = 1; i <= 100; i++){


if(i % 2 == 0) {

cout << i <<" ";

cout << "\n\n";

for (int a=1; a<=100; a+=2)

cout << " " << a << " ";

return 0;

--------------------------------------------------------------------------------------------

PROGRAM 4:

Write a program that input 10 numbers from the user in the Array and find
out Sum and Average of the Numbers using One Dimensional Array.

CODE:

#include<iostream>

using namespace std;


int main ()

int arr[10];

float average,sum=0;

for(int i=0;i<10;i++)

cout<<i+1<<"enter number"<<endl;

cin>>arr[i];

sum=sum+arr[i];

cout<<"sum of number="<<sum<<endl;

average =sum/10;

cout<<"average of number="<<average<<endl;

return 0;

PROGRAM 5:

Write a Program that display the following output on the console ”Nested
Loop”:

SHAPE 1:
CODE:

using namespace std;

main()

int squareHeight, squareWidth;

cout<< "Enter Height: ";

cin>> squareHeight;

cout<< "Enter Widht: ";

cin>> squareWidth;

for(int width=1; width<=squareHeight; width++)

if(width <= 1)

for(int width=1; width<=squareWidth; width++)

cout<< "*";

else if(width<squareHeight) {

cout<< endl;

for(int width2=1; width2<=squareWidth; width2++)

if(width2==1 || width2==squareWidth)
cout<< "*";

else

cout<< " ";

} //end of for variable width2

}// end of else if

else

cout<< endl;

for(int width3=1; width3<=squareWidth; width3++)

cout<<"*";

}//end of for having variable width3

}// end of else

}// end of first for loop

SHAPE 2:

CODE:

#include<iostream>

using namespace std;

int main ()

{
int c,d;

for(c=1;c<=5;c++)

for(d=1;d<=5;d++)

if(d>=6-c)

cout<<"*";

else

cout<<"";

cout<<"\n";

SHAPE 3:

CODE:

#include<iostream.h>
#include<conio.h>

int main()

int i,j;

clrscr();

for(i=1; i<=6; i++)

for(j=1; j<i; j++)

cout<<"*";

cout<<"\n";

getch();

SHAPE 4:

CODE:

#include<iostream>

using namespace std;

int main ()

{
int o,p;

for(o=1;o<=5;o++)

for(p=1;p<=4;p++)

cout<<"*";

cout<<endl;

return 0;

SHAPE 5:

CODE:

#include<iostream.h>

#include<conio.h>

void main()

int i, j, k;

for(i=5;i>=1;i--)
{

for(j=1;j<i;j++)

cout<<" ";

for(k=5;k>=i;k--)

cout<<"*";

cout<<"\n";

getch();

----------------------------------------------------------------------------------------------------

Program 6:

Write a Program that input 10 values from the user in the Array and find out
the Minimum value using the concepts of Searching.

Code:

#include<iostream>

using namespace std;

int main()

{
int arr[2][3];

cout<<"enter values"<<endl;

for(int x=0;x<2;x++)

for(int a=0;a<3;a++)

cin>>arr[x][a];

int min=arr[0][0];

for(int y=0;y<2;y++)

for(int b=0;b<3;b++)

if(arr[y][b]<min)

min=arr[y][b];

cout<<"minimum value="<<min;
return 0;

----------------------------------------------------------------------------------------------------

Program 7:

Write a program that input 10 numbers from the user in the Array and find
out Sum and Average of the Numbers using One DimensionalArray.

Code:

#include<iostream>

using namespace std;

int main ()

int arr[10];

float average,sum=0;

for(int i=0;i<10;i++)

cout<<i+1<<"enter number"<<endl;

cin>>arr[i];

sum=sum+arr[i];

cout<<"sum of number="<<sum<<endl;
average =sum/10;

cout<<"average of number="<<average<<endl;

return 0;

----------------------------------------------------------------------------------------------------

Program 8:

Write a program that perform “Passing Array to Function” with any program
example

Code:

#include <iostream>

using namespace std;

void display(int m[5]) {

cout << "Displaying marks: " << endl;

for (int i = 0; i < 5; ++i) {

cout << "Student " << i + 1 << ": " << m[i] << endl;

int main() {

int marks[5] = {18, 76, 90, 61, 169};


display(marks);

return 0;

PROGRAM 9:

Write a program that perform y program example “Math Functions(Built-in-


Functions)” with an

CODE:

#include <iostream>

#include<math.h>

using namespace std;

int main()

double x = 13.2;

double result = sinh(x);

cout << "sinh(13.2) = " << result << endl;

double y = 90;

cout << "sinh(90) = " << sinh(y) << endl;

return 0;

}
----------------------------------------------------------------------------------------------------

PROGRAM 10:

Write a Program that input radius of Circle and this radius “pass by value”
as FunctionArguments and display Area of Circle.

CODE:

#include<iostream>

using namespace std;

int black (float r)

float pi=3.14;

float area=pi*r*r;

cout<<"area of circle="<<area<<endl;

return 0;

int main ()

float r;

cout<<"enter radius of circle"<<endl;

cin>>r;

black (r);

You might also like