Sample code for calculating average of numbers

We will ask users to enter two integers and then calculate the average by adding and then dividing the sum by 2. As we are likely to get decimal values as result so we will declare all our variables as float only. Here is the sample code.
#include <stdio.h>
int main(void){
float num1,num2,avg;

	printf("Enter the first number  ");
	scanf("%f",&num1);
	printf("Enter the second number ");
	scanf("%f",&num2);
	avg=(num1+num2)/2;
	printf("Average  of two numbers = %4.2f", avg);
	return 0;
}
This code can be modified to include more integers for average value calculation.

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    md raihan

    31-07-2016

    Thank u so much.....for given us a simple code that complete my assignment..so thank u....so much..sir..

    g v divyaklakshmi

    30-08-2016

    thank u very much . its is very use full for us in right time
    that guy

    31-12-2016

    Thank you so much. it helps so much for my project. But there are still errors, can u help me with that?
    riddhi

    03-10-2017

    how to find avg in simple method

    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer