Saturday, May 24, 2014
If condition in C: Getting the average from a given list of input with variation
#include<stdio.h>
main()
{
int a, input[1000];
int choice;
int num,max,low;
double total=0,average;
int array[1000];
clrscr();
start:
clrscr();
printf("\n ******** MENU **********\n");
printf(" [1] Input as many numbers as the user like and ends getting of numbers when -1 is inputted.\n");
printf(" [2] Getting the largest, lowest and average in a list of numbers.\n");
printf(" Enter choice : ");
scanf("%d", &choice);
if(choice==1)
{
clrscr();
for(a=0;a<1000;a++)
{
printf("Enter number : ");
scanf("%d",&input[a]);
if(input[a]==-1)
{
goto start;
getch();
}
}
}
if(choice==2)
{
clrscr();
printf("Enter number of list :");
fflush(stdin);
scanf("%d",&num);
for(a=0;a<num;a++)
{
printf("Enter number:");
scanf("%d",&array[a]);
if (a==0)
{
max=array[a];
low=array[a];
}
if(array[a]>max)
max=array[a];
if(array[a]<low)
low=array[a];
total+=array[a];
}
average=total/num;
fflush(stdout);
printf("LOWEST = %d.\n",low);
printf("LARGEST = %d.\n",max);
printf("AVERAGE = %lf.\n",average);
}
getch();
return 0;
}
Subscribe to:
Post Comments (Atom)
Part 7. Commercial Law. Piercing the viel. Solidary liability
Because a corporation’s existence is only by fiction of law, it can only exercise its rights and powers through its directors, officers, or...
-
Adding a network printer in Linux Mint is easy. Just follow the following instructions to be able to connect to your network printer: 1. ...
-
There are really a lot of ways on how to answer bar examinations. But exploring these different versions in the actual bar exams may not be ...
-
#Uber #Grab Why grow interest upon the issues below? Well, this will help us enlighten our minds on how the modern world has grown so m...
No comments:
Post a Comment