[Courses] [C] Beginner's Lesson 4A: Arrays, Qualifiers,
and Reading Numbers
atua at gmx.co.uk
atua at gmx.co.uk
Sat Oct 12 00:16:47 EST 2002
Hi,
>u> #include "stdio.h"
>
>Always do #include <stdio.h>. stdio.h is a header file not written by
>you :-)
>
>u> int main(void)
>u> {
>u> float data[5]={34.0,27.0,45.0,82.0,22.0};
>u> double total;
> int a;
> for(a=0; a<sizeof(data)/sizeof(int); ++a)
> total+=data[a];
>u> printf("total: %.2f, average: %.2f.\n",total,total/5.0);
>since total is a double, do %.2lf instead of %.2f.
For the terminating part of the for loop, why isn't it
a<sizeof(data)/sizeof(float), since data is an array of floats and not
integers?
KWL
More information about the Courses
mailing list