bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_2 / practice / prac_011.cpp

prac_011.cpp (840B)


      1 /* average of elements */
      2 
      3 #include <iostream>
      4 using namespace std;
      5 
      6 class avarage {
      7     int inp[100], sum = 0, n, i;
      8     float avg;
      9 
     10 public:
     11     void input();
     12     void calculation();
     13     void output();
     14 };
     15 
     16 void avarage::input() {
     17     cout << "\nEnter the number of elements : ";
     18     cin >> n;
     19     i = 0;
     20     while (i < n) {
     21         cout << "\nEnter the element no " << i + 1 << " : ";
     22         cin >> inp[i];
     23         i++;
     24     }
     25 }
     26 
     27 void avarage::calculation() {
     28     i = 0;
     29     for (i = 0; i < n; i++) {
     30         sum = sum + inp[i];
     31     }
     32     avg = (float)sum / n;
     33 }
     34 
     35 void avarage::output() {
     36     i = 0;
     37     cout << "\nAvarage of the element ";
     38     for (i = 0; i < n; i++) {
     39         cout << "  " << inp[i];
     40     }
     41     cout << "   is : " << avg;
     42 }
     43 
     44 int main() {
     45     avarage z;
     46     z.input();
     47     z.calculation();
     48     z.output();
     49     return 0;
     50 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror