+ 2
C++ program input 3 values and do offset
Hello I have a given task following is requirements. C++ program which take 3 values start_values end_values offset_value. E.g : if start is given as 13 and end as 35 and offset is 5. Out put will be : 13 18 23 28 33 Sum: 115 Average: 23 Can i have this source code.
4 Antworten
+ 4
https://code.sololearn.com/cgWceL1DEJhw/?ref=app
This may help
#include <iostream>
using namespace std;
int main() {
int start, end, off;
double avg,sum;
cin>>start>>off>>end;
cout<<"Start Value: "<<start<<endl;
cout<<"Offset: "<<off<<endl;
cout<<"End Value: "<<end<<endl;
for(int i=start;i<=end;i+=off){
cout<<i<<endl;
sum+=i;
}
cout<<"sum ="<<sum<<endl;
int n=end/off;
avg=sum/n;
cout<<"average="<<avg;
return 0;
}
+ 3
Hm... If you have time, you can try the C++ tutorial on here. This problem can be solved using a for loop and some simple math.
Hint: in for (int x = 0; x < y; ++x), ++x can be anything (i.e. x += 5 (x equals x + 5)).
0
Show your attempts to solve the problem. We have lives to live and some of us have homework to do as well.
0
I tried with it mathematically but i cant convert it to c++ code. I very beginner on it in my high school.