0
Calculating averages of numbers with loops and arrays
How do I calculate the average of prompted numbers using loops and arrays?
14 ответов
+ 6
I got this to work, but it gives the wrong answer.
I tried using a loop to input data, but it didn't work. I'll have to study it some more.
https://code.sololearn.com/WV6zfFQm2qsV/?ref=app
+ 6
another way might be to make a button in HTML and send the input to JS.
I'm a bit of a noobie with this too.😞
+ 4
//in C++
#include <iostream>
using namespace std;
int main(){
int array1[4]={1,3,5,7};
int average, sum=0;
for (int i=0; i<4; i++) {
sum += array1[i]; }
average=sum/4;
cout<<average;
return 0;
}
+ 4
love, it's similar, but without #include, using and int main(). I'm gonna try one out in playground.
+ 4
I'm not an expert in JS, so I'd have to look it up. wait a few minutes...
+ 3
I think you have to use a prompt and another "for" loop to input the data into the array.
+ 3
// created by arif ansari in c++
#include<iostream>
using namespace std;
int main()
{
int a[10]={2,3,5,2,4,6,6,3,2,4}
int s=0,av;
for(int i=0;i<10;i++)
{
s+=a[i];
av=s/10;
}
cout<<"average ="<<av;
return 0;
}
//i hope this might help...
0
How bout in JavaScript
0
Thanks. It works. What if you want to prompt the user for those numbers that need to be averaged?
0
Thanks. It works. What if you want to prompt the user for those numbers that need to be averaged?
0
How exactly should I do it. Cause the average I'm getting is not accurate
0
Ok. Thank you so much
0
Nice