Program To Display Sum And Average Of All Digits Between The Lower And Upper Limit Values
/* PROGRAM TO DISPLAY SUM AND AVERAGE OF ALL DIGITS BETWEEN THE LOWER AND UPPER LIMIT VALUES (INCLUSIVE OF BOTH ; IF THE USER ENTERS LOWER VALUE GREATER THAN UPPER THEN SWAP THE VALUES) */ #include
#include
void main() { int n1,n2,t,j=0,sum=0; float avg; clrscr(); printf("\nEnter the lower and upper values\n\n"); scanf("%d%d",&n1,&n2); if(n1>n2) { t = n1; n1 = n2; n2 = t; } while(n1<=n2) { sum = sum+n1; j++; n1++; } avg = (float)sum/j; printf("\nsum = %d\n\navg = %f",sum,avg); getch(); }
Please send comments to
vgdarur.javafive@blogger.com
Copyright © 2008 - iForeRunner.com
http://www.iforerunner.com/