Answer to Question #274057 in C++ for Amit

Question #274057

Write a program that prompts the user to input two numbers, First and diff. The program then creates a one dimensional array of 10 elements and initializes them with an arithmetic sequence. The first number of the sequence is the First value and the next number is generated by adding the diff to the number preceding it. This formula is repeated for the rest of the sequence. E.g. if First =11 and diff = 4, then the arithmetic sequence will be 11, 15, 19, 23, 27, 31 ... and so on.


1
Expert's answer
2021-12-10T06:38:49-0500
#include <iostream>
using namespace std;
int main(){
    int first, diff;
    cout<<"Enter First: ";
    cin>>first;
    cout<<"Enter diff: ";
    cin>>diff;
    int array[10];
    array[0] = first;
    for(int i = 1; i < 10; i++){
        array[i] = array[i - 1] + diff;
    }
    cout<<"The arithmetic sequence is\n";
    for(int i = 0; i < 10; i++){
        cout<<array[i];
        if(i != 9){
            cout<<", ";
        }
    }
    cout<<endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment