0% found this document useful (0 votes)
28 views

Assignment of Cs201

The document contains C++ code for a program that allows a user to enter integer values into an array, then perform operations on and display the array. The program uses a menu to let the user choose to enter values, display the array normally or reversed, show multiples of 3, or calculate the sum of elements. It includes functions to get input, display the array, reverse it, filter multiples of 3, and calculate the sum.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Assignment of Cs201

The document contains C++ code for a program that allows a user to enter integer values into an array, then perform operations on and display the array. The program uses a menu to let the user choose to enter values, display the array normally or reversed, show multiples of 3, or calculate the sum of elements. It includes functions to get input, display the array, reverse it, filter multiples of 3, and calculate the sum.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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;
}

You might also like