CS201 Assignment No 1 Spring Solution👇👇👇👇
#include <iostream>
using namespace std;
double fallingDistance(double time)
{
const double g = 9.8;
double distance = 0.5 * g * time * time;
return distance;
}
int main()
{
const int numTimes = 5;
double sumDistances = 0;
int i = 1;
int count = 9;
while (i <= count)
{
double distance = fallingDistance(i);
sumDistances += distance;
cout << "Distance for time " << i << " seconds: " << distance << " meters\n";
i += 2;
}
double averageDistance = sumDistances / numTimes;
cout << "Average distance covered: " << averageDistance << " meters\n";
return 0;
}
Download solution file 👇👇