Program Discussion :: Basics
317 / 279
Write a C program using command line arguments which will take numbers as input and Find the average of the numbers.
Answer:
#include
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
Asked In ::
Language:
Om Prakesh
28 Oct, 2017 4:48 PM
#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);
}