Sie sind auf Seite 1von 3

#include <iostream>

#include <stdlib.h>
using namespace std;

// if you want changing in it. Just change variable names your assignment
will be save from copyright

// subscribe channel for more assignment solution Thanks

int array[5]; // array elements limit 5


int count=0; // count array elements
int getvalues() // getting values from users
{
int i;

cout<<"Enter Data In Array\n";


for( i=0; i<5; i++)
{
cout<<"Enter Value:";
cin>>array[i]; //pass i variable to array
count++;
}
cout<<i<<"elements entered\n";
}
void displayArray() //2nd function show all elements
{
cout<<"Now the ALl element of the Array is : \n";
for(int i=0; i<5; i++)
{
cout<<array[i]<<'\n';
}
}
void multipleOf3() // 3rd function show elements multiple by 3
{
cout<<"Now the Multiplye Each Element by 3 Array is : \n";
for(int i=0; i<5; i++)
{
cout<<array[i]*3<<'\n';
}
}
void sumOfElements() // 4th function sum of all elements
{
cout<<"Now the Some of the Array is : \n";
int sum=0;
for(int i=0; i<5; i++)
{

sum=array[i]+sum;

}
cout<<sum<<'\n';
}
void reverseArray()
{
int i, j, temp; // for reversing elements

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


int temporary = array[i];
array[i] = array[(5 - 1) - i];
array[(5 - 1) - i] = temporary;

}
cout<<"Now the Reverse of the Array is : \n";
for(i=0; i<5; i++)
{
cout<<array[i]<<" "<<'\n';
}
}

main()
{
int choice;
char b;
do{

cout<<"Press 1 To Enter Values In Array\n";


cout<<"Press 2 To Read Array Elements.\n";
cout<<"Press 3 To Show Array Elements In Reverse Order.\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\n";
cout<<"Enter your choice";
cin>>choice;
switch(choice)
{
case 1:
getvalues();
break;
case 2:

if(count==0) //validate user enter value in array or


not
{
cout<<"Array Empty First Enter Elements\n";
}else // if yes function call success
{

displayArray();
}
break;
case 3:
if(count==0)
{
cout<<"Array Empty First Enter Elements\n";
}else
{
reverseArray();
}
break;
case 4:
if(count==0)
{
cout<<"Array Empty First Enter Elements\n";
}else
{
multipleOf3();
}
break;
case 5:
if(count==0)
{
cout<<"Array Empty First Enter Elements\n";
}else
{
sumOfElements();
}
break;
case 6:
exit(0);

}
cout<<"Do you want back Y/N"; // for continue programm if user enter y
loop again start
cin>>b;
}while(b=='y' || b=='Y');
return 0;
}

Important For You – Bookmark This Page http://bit.ly/vucodes (Vu Study Groups By
Subject Codes Wise) in Your Browser for easy access In Future By
https://vustudents.ning.com/

Das könnte Ihnen auch gefallen