I am trying to write a program that will find the largest value in an array, and also will display the subscript of the largest value. I can find the largest value, but I have been working for the past 4 hours trying to get the subscript to display... anyone know how to go about this, without completely changing my program? This is a rather simple program; I am just having a mental block!!!
ARRAY:
#include <stdafx.h>
#include <stdio.h>
#define x 5
int
main(void)
{
double arr[x];
int i,
large;
/* Get Data */
printf("Enter %d numbers\n> ", x);
for (i = 0; i < x; ++i)
scanf("%lf", &arr);
large = arr[0];
for(i = 1; i < x; ++i)
if(arr > large)
large = arr;
printf("The largest value, %d has a subscript of x[%1d].", large, i);
return(large);
}
ARRAY:
#include <stdafx.h>
#include <stdio.h>
#define x 5
int
main(void)
{
double arr[x];
int i,
large;
/* Get Data */
printf("Enter %d numbers\n> ", x);
for (i = 0; i < x; ++i)
scanf("%lf", &arr);
large = arr[0];
for(i = 1; i < x; ++i)
if(arr > large)
large = arr;
printf("The largest value, %d has a subscript of x[%1d].", large, i);
return(large);
}