Home / Programs / Find the Average of Two numbers using Command Line Language
Programming Example

Find the Average of Two numbers using Command Line Language

👁 753 Views
💻 Practical Program
📘 Step by Step Learning
Find the Average of Two numbers using Command Line Language

Program Code

#include <stdio.h>

int main(int argc, char * argv[])
{
    int  sum = 0,i = 1,count = 0;
    if(argc == 1)
    {
         printf("Enter the number \n");
         exit(1);
    }
    count = argc - 1;
    while (i <= count )
    {
       sum += atoi (argv[i]) ;
       i++;
    }
      printf("Avg of the numbers.%d\n", sum/count);
}

Output

10 12

Avg of the numbers.11


Explanation

Nope

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.