rabbinur

to store in array & calculate sum, maximum and minimum

Aug 22nd, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3.  void main()
  4.  {
  5.   int i, n, sum=0;
  6.   int x[100];
  7.   clrscr();
  8.   cin>>n;
  9.   int j=0;
  10.   for(i=1; i<=n; i++)
  11.   {
  12.     x[j]=i;
  13.     cout<<i<<endl;
  14.     j++;
  15.     sum=sum+i;
  16.    }
  17.  
  18.   cout<<"sum of n numbers="<<sum<<endl;
  19.   float avg;
  20.   avg=sum/(float)i;
  21.   cout<<"avg="<<avg<<endl;
  22.  
  23.   int small;
  24.   small=x[0];
  25.   for(i=1; i<=n; i++)
  26.  
  27.    if(small>x[i])
  28.   {
  29.    small=x[i];
  30.   }
  31.    cout<<"searching---"<<endl;
  32.    cout<<"The smallest value in the given value array is ="<<small<<endl;
  33.    int biggest;
  34.    biggest=x[0];
  35.    for(i=1; i<=n; i++)
  36.     if(biggest<x[i])
  37.    {
  38.     biggest=x[i];
  39.    }
  40.     cout<<"searching---"<<endl;
  41.     cout<<"The biggest value in the given array is ="<<biggest<<endl;
  42.  
  43.   getch();
  44.  }
Advertisement
Add Comment
Please, Sign In to add comment