You are on page 1of 9

1

2 int i=0, even=0,


odd=0, zero=0,
num
float area, i++
peri, l, w

If Input
Input i<=9?
T num
l,w

F
area=l*w A
If
num==0 zero=zero+1
peri=2*(l+w) ? T

zero
F
area, peri

A If
num%2= even=even+1
3
0? T

float PI=3.1416, even


radius, area F
odd=odd+1
Input
radius
odd

area=PI*radius*radius

area

A
4

int i=0, positive=0,


negative=0, zero=0
positive,
i++ negative,
zero

T
If Input If positive=positive+1
i<=9? num num>0?
T
F
F

If negative=negative+1
num<0?
T

zero=zero+1
5

int input, input1,


counter=0, max=0,
min=0

Input
input1

min=input1
min max i++

If If
counter Input min=input
input
<=1? input
T <min? T

F F
A

If max=input
5 num<0?
T

Input F
Run

If T
Run==’n’ || A
Run==’N’?

F
B
Algorithm:
1. Start.
2. Initialize float arr[10], store=0. and int i=0, j=0.
3. for (i=0;i<=9;i++). then enter arr[i].
4. for (i=0;i<=9;i++), then for (int j=0;j<=9;j++).
If (arr[i]<arr[j]), then
store=arr[i].
arr[i]=arr[j].
arr[j]=store.
5. for (int i=0;i<=9;i++), then display arr[i]
6. Stop.

Flowchart:

Start

float arr[10],
store=0.
int i=0, j=0.

If T If T If T If T
Input
i<=9 ? i<=9 ? j<=9 ? arr[i]< A
arr[i]
arr[j]?

F F F
F
Stop B B
B

store=arr[i] T
A If
arr[i]=arr[j] arr[i]
j<=9 ?
arr[j]=store

F
B
B
#include<iostream>
using namespace std;

int main()
{
float arr[10], store=0;
int i=0, j=0;

cout<<"Enter 10 numbers: ";

for (i=0;i<=9;i++)
{
cin>>arr[i];

for (i=0;i<=9;i++)
{
for (int j=0;j<=9;j++)
{
if (arr[i]<arr[j])
{
store=arr[i];
arr[i]=arr[j];
arr[j]=store;
}
}
}
cout<<"----------------------------------------"<<endl;
cout<<"The inputted numbers in accsending are: "<<endl;
for (int i=0; i<=9; i++)
{
cout<<" "<<arr[i];
cout<<endl;

}
cout<<"----------------------------------------"<<endl;
system("pause");
return 0;
}
#include <iostream>

using namespace std;

int main()
{
char Run = true;
do
{
int menu;
cout<<"-----------------------------------"<<endl;
cout<<"---------- M E N U ----------"<<endl;
cout<<"(1) Odd, Even, Zero"<<endl;
cout<<"(2) Area and Perimeter of a Rectangle"<<endl;
cout<<"(3) Area and Perimeter of a Circle"<<endl;
cout<<"(4) Positive, Negative, Zero of an Integer"<<endl;
cout<<"(5) Largest and Smallest"<<endl;
cout<<"(0) Exit the Program"<<endl;
cout<<"-------------------------------"<<endl;
cout<<endl;
cout<<"-------------------------------"<<endl;
cout<<"Enter your choice: ";
cin>>menu;
cout<<endl;
cout<<"-----------------------------------"<<endl;
{
if(menu==1)
{
int i=0, even=0, odd=0, zero=0, num;
for(i=0;i<=9;i++)
{
cout<<" Enter an integer: ";
cin>>num;
if (num==0)
{
zero = zero+1;
}
else if(num%2==0)
{
even = even+1;
}
else
{
odd = odd+1;
}
}
cout<<"-----------------------------------"<<endl;
cout<<"Total Even is: "<<even<<endl;
cout<<"Total Odd is: "<<odd<<endl;
cout<<"Total Zero is: "<<zero<<endl;
cout<<"-----------------------------------"<<endl;
}
if(menu==2)
{
float area, peri, l, w;

cout<<"Enter the Length value: ";


cin>>l;
cout<<endl;
cout<<"Enter the Width value: ";
cin>>w;

area = l*w;
peri = 2*(l+w);

cout<<"The area of rectangle is: "<<area<<endl;


cout<<"The perimeter of rectangle is: "<<peri<<endl;
}
if(menu==3)
{
float PI=3.1416, radius, area;
cout << "Enter radius of circle\n";
cin >> radius;
area = PI*radius*radius;
cout << "Area of circle : " << area;
}
if(menu==4)
{
int i=0, positive=0, negative=0, zero=0, num;

for(i=0;i<=9;i++)
{
cout<<" Enter an integer: ";
cin>>num;
if (num>0)
{
positive = positive+1;
}
else if(num<0)
{
negative = negative+1;
}
else
{
zero = zero+1;
}
}
cout<<"-----------------------------------"<<endl;
cout<<"Total Positive is: "<<positive<<endl;
cout<<"Total Negative is: "<<negative<<endl;
cout<<"Total Zero is: "<<zero<<endl;
cout<<"-----------------------------------"<<endl;
}
if(menu==5)
{
int input, input1;
int tmp;
int counter = 0;
int max=0;
int min=0;
cout << "Enter a number: " << endl;
cin >> input1;
min=input1;

while (counter <= 1)


{
cout << "Enter a number: " << endl;
cin >> input;
if (input < min)
{
min = input;
counter++;
}
else if (input > max)
{
max = input;
counter++;
}
else
{
counter++;
}
}
cout << "min: "<< min << endl;
cout << "max: " << max << endl;
}
if(menu==0)
{
cout << "Exit the Program?"<<endl;
cout << "Y/N"<<endl;
cin>>Run;
if (Run == 'n' || Run == 'N')
main();
else
return 0;
}
}
}

while (Run);
system("pause");
return 0;

}
ITC 104L

Marlon Oledan Solmiano Jr.


BSIT 3

Ms. Adela Onlao


Instructor

You might also like