Please write a simple C program for the following requiremen

Please write a simple C program for the following requirement:

Write a program that will prompt the user to input ten integer values (insert these values into an array). Then find out the smallest and greatest of those values.

Thank you for the help!

Solution

C program to get 10 input values from user and then to print smallest and greatest value among them

#include <stdio.h>
int main()
{
    int arr[10], size, i, small, great;
    printf(\"\ Input the size of the array : \");
    scanf(\"%d\",&size);
    printf(\"\ Enter %d values in to the array: \", size);
    for(i=0;i<size;i++)
    scanf(\"%d\",&arr[i]);

    great=arr[0];
    for(i=1;i<size;i++){
      if(great<arr[i])
           great=arr[i];
}
    printf(\"Greatest Value: %d\",great);   

   /* To compute smallest value*/

    small=arr[0];
    for(i=1;i<size;i++){
      if(small>arr[i])
           small=arr[i];
}
printf(\"Smallest Value: %d\",small);
    return 0;
}

Sample Input Values :

Input the size of the array : 10

Enter 10 values in to the array: 3 6 9 8 12 34 1 4 5 7

Greatest Value: 34

Smallest Value: 1

Please write a simple C program for the following requirement: Write a program that will prompt the user to input ten integer values (insert these values into a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site