Tuesday, May 24, 2016

NIELIT M3-R4: Q.No. 6(b) July 2013

M3-R4: July 2013 (O-Level)

Q. 6(b):
Write a ‘C’ program to compute the average of every third integer lying between 1 and 200? Include appropriate documentation.

Ans:
Program to compute the average of every third integer between 1 and 200. Here are assuming 1 and 200 inclusive:

#include <stdio.h>
#include <conio.h>

void main(){
    float average;
    int i, sum=0, n=0;
    for(i=1; i<=200; i+=3){
        sum = sum + i;
        n++;
    }
    average = (float) sum / n;
    printf("\nAverage = %f", average);
    getch();
}

No comments:

Post a Comment