write a c program to find the largest element and also print its position in the array
Answers
Answer:
see the answer below
Explanation:
Given an array, find the largest element in that given array. ... C++ program to find maximum ... We use std:: max_element in C++. ... print (largest(arr, n)).
Answer:
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
void selection_sort(int arr[] , int len)
{
for(int i = 0; i < len - 1; i++)
{
int min = i;
for(int j = i + 1; j < len; j++)
{
if(arr[j] < arr[min])
{
min = j;
}
}
int temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
}
int main()
{
srand(time(NULL));
int arr[10];
int len = sizeof(arr)/sizeof(arr[0]);
for(int i = 0; i < len; i++){
int ran = rand() % 100;
arr[i] = ran;
}
selection_sort(arr , len);
for(int i = 0; i < len; i++){
printf("%d " , arr[i]);
}
printf("\n");
printf("The largest number in the array is %d" , arr[len-1]);
return 0;
}
Explanation: