In C language:
Partially finished program is given below. The second and third parameters of the count() function need to be pointer parameters. However, the programmer forgot to write the necessary ampersands and asterisks in the prototype, call, function header, and function code. Add these characters where needed so that changes made to the parameters adults and teens actually change the underlying variables in the main program.
#include
#define MAX 10
void count( int ages[], int adults, int teens );
int main( void )
{
int family[MAX] = {44, 43, 21, 18, 15, 13, 11, 9, 7};
int Nadults=0, Nteens=0, Nkids=0;
puts ( "\nFamily Structure" );
count ( family, Nadults, Nteens );
Nkids = MAX - (Nadults + Nteens);
printf( "Family has %i adults, %i teens, %i kids\n",Nadults, Nteens, Nkids );
puts( "----------------------------------------\n" );
return 0;
}
void count( int ages[], int adults, int teens )
{
int k;
for (k = 0; k < MAX; ++k)
{
if ( ages[k] >= 18 )
++ adults;
else if ( ages[k] >= 13 )
++ teens;
}
}
#include <stdio.h>
#define MAX 10
void count( int ages[], int* adults, int* teens );
int main( void )
{
int family[MAX] = {44, 43, 21, 18, 15, 13, 11, 9, 7};
int Nadults=0, Nteens=0, Nkids=0;
puts ( "\nFamily Structure" );
count ( family, &Nadults, &Nteens );
Nkids = MAX - (Nadults + Nteens);
printf( "Family has %i adults, %i teens, %i kids\n",Nadults, Nteens, Nkids );
puts( "----------------------------------------\n" );
return 0;
}
void count( int ages[], int* adults, int* teens )
{
int k;
for (k = 0; k < MAX; ++k)
{
if ( ages[k] >= 18 )
++ *adults;
else if ( ages[k] >= 13 )
++ *teens;
}
}
Get Answers For Free
Most questions answered within 1 hours.