[ create a new paste ] login | about

Link: http://codepad.org/qCf2W7n0    [ raw code | output | fork ]

C, pasted on Feb 14:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
int main(){
    int n = 3;
    float arr[3] = {10, 20, 30};
    float m = 0;
    int i;
    float sum = 0;

    for(i = 0; i < n; i++)
        m = arr[i] > m ? arr[i] : m;

    for(i = 0; i < n; i++){
        arr[i] = arr[i]/ m * 100;
        sum += arr[i];
    }
    printf("%.2f", sum / n);
    return 0;
}


Output:
1
66.67


Create a new paste based on this one


Comments: