0
Write a C++ program that adds numbers...first let the user decide on the numbers he wants to use and add them all together?
C
10 Respostas
+ 12
Is this what you want?
#include<iostream>
using namespace std;
int main ()
{
int n = 0;
double num = 0.0;
double sum = 0.0;
cout << "How many number? "; cin >> n;
for(int i = 1; i <= n; i++) {
cout << "#" << i << ": "; cin >> num;
sum += num;
}
cout << "The total is: " << sum << endl;
}
+ 12
So give me more details about what you want.
+ 11
So, you'd prefer the output be like this?
Example
#1: 34
#2: 12
#3: 65
...
34 + 12 + 65 = 111
+ 11
If so, try this.
[https://code.sololearn.com/ca98TslAejXD]
+ 4
in c language
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
printf("enter how many numbers u would like to add");
scanf("%d",&n);
float a;
float sum;
int i;
sum=0;
for(i=1;i<=n;i++)
{
scanf("%d",a);
sum=sum+a;
}
printf("the sum of all elements is %d",sum);
getch();
}
+ 3
sorry the above is wrong
below is correct
give
input:
3[means no.of elements]
1
2
3[these three are the numbers u are going to add]
now output will be:
1
2
3
sum of elements is :6
+ 3
this one works for your question......
0
no...its wrong
0
okay....I want a program where me as a user I will input the number of values I want...then add each of them together to print out the sum.