C program to Given a vector (integer or real), determine what is the maximum value of element what is the position in which this element is located

How to write a C program to Given a vector (integer or real), determine what is the maximum value of element what is the position in which this element is located ?



Soution For C Program:

#include <stdio.h>

int trova_max(int vettore[], int n){

int i,max;
max=0;

for (i=0; i<n; i++){
if (vettore[i]>max)
max=vettore[i];
}
return max;
}

int main(void){
int n;
printf("Inserire quanti elementi deve avere il vettore: \n");
scanf("%d", &n);

int vettore[n];

for(int i=0; i<n; i++){
printf("Inserire l'elemento %d: \n", i+1);
scanf("%d",&vettore[i]);
}

printf("Il massimo del vettore inserito รจ: %d", trova_max(vettore,n));
return 0;
}


Learn More :