Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Test expression



Header file



" ; " after loop



Specifer



Working with switch case




Calculate sum and average of first N natural number



// AHF C PROGRAM SOLVING

//solving here ITERATIVES STATEMENTS type of programming problem

#include<stdio.h> #include<math.h> #define pf printf int main() { int n,j,sum=0; float ave; //taking the number to continue loop pf("Enter any integer number: "); scanf("%d",&n); for(j=0;j<=n;j++) sum+=j; //typecast sum into float return type ave=(float)sum/n; pf("\nThe summation of first %d natural number is : %d",n,sum); pf("\nThe average of first %d natural number is : %f",n,ave); return 0; }
OUTPUT:


© 2018 - All rights reserved