



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




int main(){
int index;
/* loop variable */
double sumsquares = 0;
/* result of summing the squares */
/* loop over each number, adding its square to the sum */for ( index = 1; index <= 10; index++ ){
/* compute the square of the index and add to the sum
sumsquares = sumsquares + index * index; } printf("The sum of the squares from 1 to 10 is %4.2lf.\n", sumsquares);
return(0);
int main() {
int index;
/* loop variable */
double sumsquares = 0;
/* result of summing the squares */
/* loop over each number, adding its square to the sum */for ( index = 1; index <= 10; index++ ) {
/* compute the square of the index and add to the sum
sumsquares = sumsquares + index * index; } printf("The sum of the squares from 1 to 10 is %4.2lf.\n", sumsquares);
return(0);
/* function definition */double factorial(int x){
int i; double result = 1.0;for( i = 1; i <= x; i++) { result = result * i; } // to fit function on page!return(result); } int main(void){
int number; double numberfact;printf("What factorial would you like to compute? ");scanf("%i", &number);numberfact = factorial(number);
// function call
printf("Factorial of %i is %lf\n", number, numberfact);return(0); }