Answer to Question #196533 in C++ for jimuel

Question #196533

1. Write a program that reads in a list of integer values one per line and outputs their sum as well as the numbers read with each number annotated to say what percentage it contributes to the sum. Your programs will ask the user how many integers there will be, create an array of that length, and then fill the array with the integers input. 



1
Expert's answer
2021-05-21T06:49:29-0400
#include <iostream>
using namespace std;
int main(){
    int *arr, size = 0, sum = 0;
    cout<<"Input number of integers: ";
    cin>>size;
    arr = new int[size];
    for(int i = 0; i < size; i++) {
        cin>>arr[i];
        sum += arr[i];  
    }
    cout<<"\nNumber\tPercentage\n";
    for(int i = 0; i < size; i++){
        cout<<arr[i]<<"\t"<<(float)arr[i] / sum * 100<<"%"<<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

LATEST TUTORIALS
New on Blog