Arrays in C Programming Exercises
Arrays in C Programming Exercises
1. Create a C++ program that will print the element of an array. Filename: Value
Expected Output:
Array[4]= 65
Expected Output :
151
3. Create a C++ program that will find an element in an array and display the
location of the said element. Filename: Find
Element: 67
Expected Output:
Location: Array[9]
4. Filename: SumArray
#include <iostream>
using namespace std;
int main(){
int array[10]={1,2,3,4,5,6,7,8,9,0};
int sum, loop;
sum=0;
for(loop =9; loop >=0; loop--){
sum= sum + array[loop];
}
cout<<"Sum of array is " <<sum;
return0;
}
5. Write your own C++ program that calculates the average of a given array. Array
elements must be inputted by the user. Filename: AveArray
6. Filename: Largest
#include <iostream>
using namespace std;
int main(){
int array[10]={1,2,3,4,5,6,7,8,9,0};
int loop, largest;
largest= array[0];
for(loop =1; loop <10; loop++){
if( largest < array[loop])
largest= array[loop];
}
cout<<"Largest element of array is "<<largest;
return0;
}
7. Write your own program that will find the smallest element in a given array of size 10.
Array elements must be provided by the user. Filename: Smallest
8. Filename: SecLarge
#include <iostream>
using namespace std;
int main()
{
int array[10]={101,11,3,4,50,69,7,8,9,0};
int loop, largest, second;
if(array[0]> array[1]){
largest= array[0];
second = array[1];
}else{
largest= array[1];
second = array[0];
}
}
9. Write a program in C++ to find the maximum and minimum element in an array.
Filename: MaxMin
#include <iostream>
using namespace std;
#define DIMENSION 10
int main()
{
int i;
float max, array[DIMENSION];
#include <iostream>
using namespace std;
int main()
{
int arr1[100],i,n,p,x;
return 0;
}