Steve Summit C notes , exercise
- From: "arnuld" <geek.arnuld@xxxxxxxxx>
- Date: 16 Mar 2007 23:46:28 -0700
this is the programme i created, for exercise 2, assignment 3 at
http://www.eskimo.com/~scs/cclass/asgn.beg/PS2.html
it runs fine. i wanted to know if it needs any improvement:
----------------- PROGRAMME ----------------------------
/* Steve Summit's C programming
Section 3 :: exercise 2
STATEMENT:
Write a program to compute the average of the ten numbers 1, 4,
9, ..., 81, 100,
that is, the average of the squares of the numbers from 1 to 10. (This
will be a
simple modification of Exercise 3 from last week: instead of printing
each square
as it is computed, add it in to a variable sum which keeps track of
the sum of all
the squares, and then at the end, divide the sum variable by the
number of numbers summed.)
*/
#include <stdio.h>
#define DIVISOR 10
int main()
{
int i;
double sum;
sum = 0;
for(i = 0; i <= 10; ++i)
sum += i*i;
printf("the average is: %.1f\n", sum / DIVISOR);
return 0;
}
----------------------- OUTPUT ----------------------
[arch@voodo steve-summit]$ gcc -std=c99 -pedantic -Wall -Wextra
assign-3_ex-2.c
[arch@voodo steve-summit]$ ./a.out
the average is: 38.5
[arch@voodo steve-summit]$
.
- Follow-Ups:
- Re: Steve Summit C notes , exercise
- From: santosh
- Re: Steve Summit C notes , exercise
- From: Gregor H .
- Re: Steve Summit C notes , exercise
- From: Jason Curl
- Re: Steve Summit C notes , exercise
- From: user923005
- Re: Steve Summit C notes , exercise
- From: Martin Ambuhl
- Re: Steve Summit C notes , exercise
- From: Richard Heathfield
- Re: Steve Summit C notes , exercise
- Prev by Date: Re: Unit Testing With Function Mocking
- Next by Date: Re: C89, size_t, and long
- Previous by thread: explicit casts
- Next by thread: Re: Steve Summit C notes , exercise
- Index(es):
Relevant Pages
|