C++ Programs & Stuffz

Nothing like anything!!!

Please Click on ADS!!

Please Click on the above ads given by GOOGLE , so that I can maintain my blog!!

Tuesday, August 31, 2010

Find the sum and avg of any non negative nos.

//pgm to find the sum and avg of any non negative nos.
#include<iostream.h>
#include<conio.h>
void main()
{
    int i,n,j=0,x;
   float sum=0,avg;
   cout<<"enter the value of n";
   cin>>n;
   cout<<"enter the nos.";
   for(i=1;i<=n;i++)
   {
       cin>>x;
      if(x>0)
      {
          sum=sum+x;
         j++;
      }
   }
   avg=sum/j;
   cout<<"sum="<<sum<<endl;
   cout<<"avg="<<avg;
   getch();
}

0 comments:

Post a Comment

free counters