DavidMX6
04-05-2004, 07:49 PM
Having some trouble making a program. Here's what it asks for:
Write a program to compute the sum of the series 1^3+2^3+….…+iMax^3. The user has to input the maximum value iMax for the series. The printf and scanf associated with this input for iMax should be inside the main function. The computation part should be done by a user-defined function. Call it ‘SumofCubes’. It will have one argument. The printf() for the final answer can be inside either main or the SumofCubes function.
And here is what I have so far:
#include <math.h>
#include <stdio.h>
float sumofcubes(float);
int main(void)
{
float fMax;
float fSum;
printf("Please enter a maximum value.\n");
scanf("%d", &fMax);
iSum = sumofcubes();
printf("The sum is %d", fSum);
return 0;
}
float sumofcubes(float fMax)
{
int iCount;
float fValue;
for (iCount=1; iCount<=iMax; iCount=iCount+1)
fValue=pow(iCount,3);
return(fValue);
}
Any help would be greatly appreciated! Thanks
Write a program to compute the sum of the series 1^3+2^3+….…+iMax^3. The user has to input the maximum value iMax for the series. The printf and scanf associated with this input for iMax should be inside the main function. The computation part should be done by a user-defined function. Call it ‘SumofCubes’. It will have one argument. The printf() for the final answer can be inside either main or the SumofCubes function.
And here is what I have so far:
#include <math.h>
#include <stdio.h>
float sumofcubes(float);
int main(void)
{
float fMax;
float fSum;
printf("Please enter a maximum value.\n");
scanf("%d", &fMax);
iSum = sumofcubes();
printf("The sum is %d", fSum);
return 0;
}
float sumofcubes(float fMax)
{
int iCount;
float fValue;
for (iCount=1; iCount<=iMax; iCount=iCount+1)
fValue=pow(iCount,3);
return(fValue);
}
Any help would be greatly appreciated! Thanks