Logic and Design

Number Analysis Program
Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display the following data:
• The lowest number in the array
• The highest number in the array
• The total of the numbers in the array
• The average of the numbers in the array

Questions by pokhara

Showing Answers 1 - 12 of 12 Answers

tnguyen25

  • Jun 2nd, 2014
 

Thank you for your question.

Code
  1.         private static int lowestNumberInArray(int[] numbers)

  2.         {

  3.             if (numbers.Length < 0)

  4.                 throw new ArgumentException();

  5.  

  6.             int lowest = numbers[0];

  7.  

  8.             foreach (int i in numbers)

  9.             {

  10.                 if (i < lowest)

  11.                     lowest = i;

  12.             }

  13.             return lowest;

  14.         }

  15.  

  16.         private static int biggestNumberInArray(int[] numbers)

  17.         {

  18.             if (numbers.Length < 0)

  19.                 throw new ArgumentException();

  20.             int biggest = numbers[0];

  21.  

  22.             foreach(int i in numbers)

  23.             {

  24.                 if (i > biggest)

  25.                 {

  26.                     biggest = i;

  27.                 }

  28.             }

  29.             return biggest;

  30.         }

  31.  

  32.         private static int sumOfNumbersInArray(int[] numbers)

  33.         {

  34.             if (numbers.Length < 0)

  35.                 throw new ArgumentException();

  36.             int sum = 0;

  37.  

  38.             foreach (int i in numbers)

  39.             {

  40.                 sum += i;

  41.             }

  42.             return sum;

  43.         }

  44.  

  45.         private static double averageOfNumbersInArray(int[] numbers)

  46.         {

  47.             if (numbers.Length < 0)

  48.                 throw new ArgumentException();

  49.  

  50.             return sumOfNumbersInArray(numbers) / numbers.Length;

  51.         }

  Was this answer useful?  Yes

akhilesh

  • Sep 14th, 2017
 

Int main()
{
int a[10];
for(i=0;i<10;i++)
{cin>>a[i];
}
i=0;
b= a[i];
c=b;
s=c;
avg=s;
for(i=1;i<<10;i++)
{
if(a[i] b=a[i];
if(a[i]>c)
c=a[i];
s=+a[i];
}
avg=s/10;
}

Code
  1. int main()

  2. {

  3. int a[10];

  4. for(i=0;i<10;i++)

  5. {cin>>a[i];

  6. }

  7. i=0;

  8. b= a[i];

  9. c=b;

  10. s=c;

  11. avg=s;

  12. for(i=1;i<<10;i++)

  13. {

  14. if(a[i]<b)

  15. b=a[i];

  16. if(a[i]>c)

  17. c=a[i];

  18. s=+a[i];

  19. }

  20. avg=s/10;

  21. }

  22.  

  23.  

  Was this answer useful?  Yes

Shubhangi

  • Oct 5th, 2017
 

I inserted a code but how to get exact decimal point answer for avg,I didnt get .

Code
  1. #include<stdio.h>

  2. main()

  3. {

  4. int arr[10];

  5. int i,size;

  6. size=sizeof(arr)/sizeof(arr[0]);

  7. printf("enter the array elemrnt......

  8. ");

  9.  

  10. for(i=0;i<size;i++)

  11. //scanf("%d",&arr[i]);

  12. arr[i]=rand()%100;

  13.  

  14. for(i=0;i<size;i++)

  15. printf("%d      ",arr[i]);


  16. ");

  17.  

  18. //lowest number....

  19. int temp=arr[0];

  20. for(i=1;i<size;i++)

  21. {

  22. if(temp>arr[i])

  23. temp=arr[i];

  24. else

  25. continue;

  26. }

  27. printf("lowest element=%d

  28. ",temp);

  29. //highewst numer

  30.  temp=arr[0];

  31. for(i=1;i<size;i++)

  32. {

  33. if(temp<arr[i])

  34. temp=arr[i];

  35. else

  36. continue;

  37. }

  38. printf("highest element=%d

  39. ",temp);

  40.  

  41. //toatal of numbers

  42. int sum =0;

  43. for(i=0;i<size;i++)

  44. {

  45. sum=sum+arr[i];

  46. }

  47. printf("total of an array:%d

  48. ",sum);

  49. //average

  50. int avg;

  51. avg=sum/size;

  52. printf("average=%d

  53. ",avg);

  54.  

  55. }

  56.  

  Was this answer useful?  Yes

Teja

  • Oct 8th, 2017
 

int arr[] = {4,2,6,1,7,12,10,11};
int min= arr[0];
int max= arr[0];
int total = 0;
int avg;
for(int i=0; i if(min > arr[i]) {
min = arr[i];
} else if(max < arr[i]) {
max = arr[i];
}
total = total + arr[i];
}
avg = total/arr.length;
System.out.println("Min : " + min + "Max: " + max + "Total:" + total + "avg" + avg);

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions