based on the source code provided in c, how could I find the max and min values of entries in array a and b. Feel free to edit and provide comments of how I could fix it. #include #include #include #define N 10 int main(void) { int i,j,k,n, max, min; float a[N], b[N],sum; char key_hit; do { printf("Please input how many values are inside array a (from 2 to 10):"); scanf("%i", &n); }while (n<2 || n>10); printf("\n\nPlease enter array a values"); for(i=1; i<=n; i+=1) { printf("\narray a value %i. : ",i); scanf("%f", &a[i]); } do { printf("Please input how many values are inside array b (from 2 to 10):"); scanf("%i", &k); }while (k<2 || k>10); printf("\n\nPlease enter array b values"); for(j=1; j<=k; j+=1) { printf("\narray b value %i. : ",j); scanf("%f", &b[j]); } printf("\n\nIs there anything choice you would like to do?"); printf("\nThe numbers related to the choices are listed below:"); printf("\n1. Max and min values of a."); printf("\n2. Max and min values of b."); printf("\n3. Dot product of a and b."); printf("\n4. Review a specific value in the set."); printf("\n5. End the program."); printf("\nPlease enter your choice (the number): "); scanf(" %c", &key_hit); key_hit == '0'; switch(key_hit) { case '1': min = a[0]; max = a[0]; for(i=0; i<=n; i++) { if(a[i] < min) { min = a[i+1]; } if(a[i] > max) { max = a[i]; } } printf("\nThe max value entry in a is: %i", max); printf("\nThe min value entry in a is: %i", min); break; case '2': min = b[0]; max = b[0]; for(j=0; j<=k; j++) { if(b[j] < min) { min = b[j]; } if(b[j] > max) { max = b[j]; } } printf("\nThe max value entry in b is: %i", max); printf("\nThe min value entry in b is: %i", min); break; } return 0;
based on the source code provided in c, how could I find the max and min values of entries in array a and b. Feel free to edit and provide comments of how I could fix it.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define N 10
int main(void)
{
int i,j,k,n, max, min;
float a[N], b[N],sum;
char key_hit;
do
{
printf("Please input how many values are inside array a (from 2 to 10):");
scanf("%i", &n);
}while (n<2 || n>10);
printf("\n\nPlease enter array a values");
for(i=1; i<=n; i+=1)
{
printf("\narray a value %i. : ",i);
scanf("%f", &a[i]);
}
do
{
printf("Please input how many values are inside array b (from 2 to 10):");
scanf("%i", &k);
}while (k<2 || k>10);
printf("\n\nPlease enter array b values");
for(j=1; j<=k; j+=1)
{
printf("\narray b value %i. : ",j);
scanf("%f", &b[j]);
}
printf("\n\nIs there anything choice you would like to do?");
printf("\nThe numbers related to the choices are listed below:");
printf("\n1. Max and min values of a.");
printf("\n2. Max and min values of b.");
printf("\n3. Dot product of a and b.");
printf("\n4. Review a specific value in the set.");
printf("\n5. End the program.");
printf("\nPlease enter your choice (the number): ");
scanf(" %c", &key_hit);
key_hit == '0';
switch(key_hit)
{
case '1':
min = a[0];
max = a[0];
for(i=0; i<=n; i++)
{
if(a[i] < min)
{
min = a[i+1];
}
if(a[i] > max)
{
max = a[i];
}
}
printf("\nThe max value entry in a is: %i", max);
printf("\nThe min value entry in a is: %i", min);
break;
case '2':
min = b[0];
max = b[0];
for(j=0; j<=k; j++)
{
if(b[j] < min)
{
min = b[j];
}
if(b[j] > max)
{
max = b[j];
}
}
printf("\nThe max value entry in b is: %i", max);
printf("\nThe min value entry in b is: %i", min);
break;
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images