23.4k views
0 votes
Write an application that finds the smallest of several integers. Assume that the first value read specifies the number of values to input from the user. C

User WesR
by
4.4k points

1 Answer

5 votes

Answer:

Following are the code to the given question:

#include<stdio.h>//include header file

int main() //defining a main method

{

int a[100],k,x,s; //defining integer variable and an array

printf("Input the number of element want to insert array: "); //print message

scanf("%d",&x); //input value

printf("Enter array value: \\"); //print message

for(k = 0; k<x; k++) //defining a loop that inputs values

{

scanf("%d",&a[k]); //use array to input value

}

s = a[0]; //holding first array value in array

for(k=0;k<x;k++) //use for loop

{

if(a[k]<s) //use if block to check the smallest array value

{

s=a[k];//holding smallest array value

}

}

printf("smallest number= %d",s);//print smallest value

}

Output:

Please find the attached file.

Step-by-step explanation:

In this code an array and another integer variable "a[100], i,n, and s" is is declared, in which the array and n for input the value from the user-end.

In the next step, an "s" variable is declared that inputs the first array element value in s and use a loop to check the smallest array element and prints its value.

Write an application that finds the smallest of several integers. Assume that the-example-1
User Thkang
by
4.9k points