0% found this document useful (0 votes)
27 views1 page

Largest Number in Array

hh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

Largest Number in Array

hh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

#include <stdio.

h>

int main() {

int a[10], n;

int largest1, largest2, i;

printf("enter number of elements you want in array");

scanf("%d", &n);

printf("enter elements");

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

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

largest1 = a[0];

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

if (a[i] > largest1) {

largest1 = a[i];

largest2 = a[0];

for (i = 1; i < n; i++) {

if (a[i] > largest2 && a[i] < largest1)

largest2 = a[i];

printf("First and second largest number is %d and %d ", largest1, largest2);

You might also like