Assignment of Cs201
Assignment of Cs201
#include<iostream>
using namespace std;
void getValues(int ar[])
{
for (int i = 0; i < 10; i++)
{
cout<<"ENTER THE VALUE: \t";
cin>>ar[i];
}
cout<<"10 elements entered"<<endl;
}
void displyArray(int *p)
{int count=0;
for (int j= 0; j < 10; j++)
{
if (p[j]==0)
{
count=count+1;
}
}
if (count==10)
{
cout<<"ARRAY IS EMPTY, FIRST ENTER DATA IN ARRAY"<<endl<<endl;
}
else
{
for (int i = 0; i < 10; i++)
{
cout<<p[i]<<endl;
}
}
void reverseArray(int *p)
{int count=0;
for (int k= 0; k < 10; k++)
{
if (p[k]==0)
{
count=count+1;
}
}
if (count==10)
{
cout<<"ARRAY IS EMPTY, FIRST ENTER DATA IN ARRAY"<<endl<<endl;
}
else
{
for (int i = 9; i >= 0; i--)
{
cout<<p[i]<<endl;
}
}
}
void multipleOf3(int *p)
{
int count=0;
for (int k= 0; k < 10; k++)
{
if (p[k]==0)
{
count=count+1;
}
}
if (count==10)
{
cout<<"ARRAY IS EMPTY, FIRST ENTER DATA IN ARRAY"<<endl<<endl;
}
else
{
for (int i = 0; i < 10; i++)
{
if (p[i]%3==0)
{
cout<<p[i]<<endl;
}
}
}
}
void sumOfElements(int *p)
{int sum=0;
for (int i = 0; i < 10; i++)
{
sum=sum+p[i];
}
cout<<"SUM = "<<sum<<endl;
}
int main()
{
int arr[10]={0};
int choice=0;
do
{
cout<<"PRESS 1 TO ENTER DATA IN ARRAY\n";
cout<<"PRESS 2 TO READ THE ARRAY ELEMENTS\n";
cout<<"PRESS 3 TO SHOW ARRAY ELEMENTS IN REVERSE\n";
cout<<"PRESS 4 TO SHOW ARRAY ELEMENTS WHICH ARE MULTIPLES OF 3\n";
cout<<"PRESS 5 TO SHOW SUM OF ALL THE ELEMENTS\n";
cout<<"PRESS 6 TO EXIT\n";
cout<<"enter the choice\t";
cin>>choice;
if (choice==1)
{
getValues(&arr[10]);
}
if (choice==2)
{
displyArray(&arr[10]);
}
if (choice==3)
{
reverseArray(&arr[10]);
}
if (choice==4)
{
multipleOf3(&arr[10]);
}if (choice==5)
{
sumOfElements(&arr[10]);
}
if (choice==6)
{
break;
}
} while (choice!=6);
system("pause");
return 0;
}