Question
Write a C++ program to : 1. Create an integer array of size 20 Assign int values using loops such that the first element is
Write a C++ program to :
1. Create an integer array of size 20
Assign int values using loops such that the first element is 3 and every element after that is the determined by the following formula:
a[i] = a[i-1] + (3*i) if a[i-1] is an even number
a[i] = a[i-1] - (2*i) if a[i-1] is an odd number
Print array elements with each element separated by a space
Compute and print the following (with formats given in double quotes):
a. average of all array elements - "Average : "(value)
b. maximum element - "Maximum value : "(value)
c. minimum element - "Minimum value : "(value)
d. number of elements divisible by 5 - "Count of numbers divisible by 5 : "(value)
Ensure every statement is printed on a new line.
#include
int main() { //declare array //assign values to array //print array elements //compute and print average //compute and print maximum value //compute and print minimum value //compute and print count of array elements divisible by 5 return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started