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 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);
}
                        

🖥 Program Output

10 12

Avg of the numbers.11



                            

📘 Explanation

Nope
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.