Developer community
0 votes
224 views
asked by Expert (13.2k points) 27 41 59 | 224 views

1 Answer

0 votes
Program:

#include <stdio.h>

int main() {

int a[10];

int i;

int greatest;

printf("Enter ten values:");

//Store 10 numbers in an array

for (i = 0; i < 10; i++) {

scanf("%d", &a[i]);

}

//Assume that a[0] is greatest

greatest = a[0];

for (i = 0; i < 10; i++) {

if (a[i] > greatest) {

greatest = a[i];

}

}

printf("\nGreatest of ten numbers is %d", greatest);

return 0;

}

Output:

Enter ten values: 2 53 65 3 88 8 14 5 77 64 Greatest of ten numbers is 88

Explanation with example:

Entered values are 2, 53, 65, 3, 88, 8, 14, 5, 77, 64

They are stored in an array of size 10. let a[] be an array holding these values.

/* how the greatest among ten numbers is found */

Let us consider a variable 'greatest'. At the beginning of the loop, variable 'greatest' is assigned  with the value of first element in the array greatest=a[0]. Here variable 'greatest' is assigned 2 as a[0]=2. Below loop is executed until end of the array 'a[]';.

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

{

if(a[i]>greatest)

{

greatest= a[i];

}

}

For each value of 'i', value of a[i] is compared with value of variable 'greatest'. If any value greater than the value of 'greatest' is encountered, it would be replaced by a[i]. After completion of 'for' loop, the value of variable 'greatest' holds the greatest number in the array. In this case 88 is the greatest of all the numbers.
answered by Guru (39.1k points) 10 22 34

Related questions

0 votes
2 answers
asked by john Guru (27.1k points) 33 50 98 | 75 views
+2 votes
2 answers
asked by Smita Advisor (7.1k points) 10 23 42 | 8.6k views
0 votes
1 answer
asked by sara Guru (24.6k points) 29 51 79 | 31 views
0 votes
1 answer
+2 votes
2 answers
asked by Smita Advisor (7.1k points) 10 23 42 | 2.3k views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users