#include <stdio.h>
#include <stdlib.h>
void Instruct( void );
void GetNumbers( int [] );
int FindLargest (int []);
void main()
{
int a[ 10 ];
Instruct();
GetNumbers( a );
printf("the largest value is %d\n", FindLargest(a));
system( "pause" );
}
void Instruct( void )
{
printf( "This program will determine the largest and smallest values in a set of ten numbers. ""It will also compute the sum and average of the numbers.\n\n" );
}
void GetNumbers( int [] )
{
int b[ 10 ];
int number = 0;
printf( "Please enter your list of ten numbers: " );
for ( int i = 0 ; i < 10; i++ ) {
scanf( "%d", &number );
b[ i ] = number;
}
printf( "Your array has these values: " );
for ( int i = 0 ; i < 10; i++ ) {
printf( "%d ", b[ i ] );
}
printf( "\n" );
}
int FindLargest ( int array [] )
{
int maxNumber = 0 ;
for(int i = 0; i < 10; i++)
{
if(array[i] > maxNumber)
maxNumber = array[i];
}
return maxNumber;
}
Actually, Duoas brings up a good point. Don't assume the array size will be 10; it might be a good idea to pass the array size as an extra variable. But! Get your program to work for a size 10 array first. :)
Line 27: Are we missing something here?
Line 29: Do we have something redundant here?
void GetNumbers( int b[] )
{
int number = 0;
printf( "Please enter your list of ten numbers: " );
for ( int i = 0 ; i < 10; i++ ) {
scanf( "%d", &number );
b[ i ] = number;
}
printf( "Your array has these values: " );
for ( int i = 0 ; i < 10; i++ ) {
printf( "%d ", b[ i ] );
}
printf( "\n" );
}
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
void Instruct( void );
void GetNumbers( int [], int size);
int FindLargest (int []);
void main()
{
int a[ SIZE ];
Instruct();
GetNumbers( a , SIZE);
FindLargest(a);
//printf("%d",FindMax(array));
system( "pause" );
}
void Instruct( void )
{
printf( "This program will determine the largest and smallest values in a set of ten numbers. ""It will also compute the sum and average of the numbers.\n\n" );
}
void GetNumbers( int array [], int size )
{
int b[ SIZE ];
int number = 0;
printf( "Please enter your list of ten numbers: " );
for ( int i = 0 ; i < size; i++ ) {
scanf( "%d", &number );
b[ i ] = number;
}
printf( "Your array has these values: " );
for ( int i = 0 ; i < size; i++ ) {
printf( "%d ", b[ i ] );
}
printf( "\n" );
}
int FindLargest ( int array [] )
{
int maxNumber;
int temp = array[0] ;
printf("the largest value is");
for(int i = 0; i < 10; i++)
{
if(array[i] > temp)
maxNumber = array[i];
}
return printf("%d", temp);
}
void GetNumbers( int b [], int size )
{
int number = 0;
printf( "Please enter your list of ten numbers: " );
for ( int i = 0 ; i < size; i++ ) {
scanf( "%d", &number );
b[ i ] = number;
}
printf( "Your array has these values: " );
for ( int i = 0 ; i < size; i++ ) {
printf( "%d ", b[ i ] );
}
printf( "\n" );
}
int FindLargest ( int array [] )
{
int maxNumber;
int temp = array[0] ;
printf("the largest value is");
for(int i = 0; i < 10; i++)
{
if(array[i] > temp)
maxNumber = array[i];
}
return printf("%d", temp);
}