Time for some review of multidimensional arrays (this is called interleaved learning - a method of learning that helps you retain better what you have learned!)
Please complete the following program so that the function maxTemp() finds the maximum value stored in the array passed to it. Be sure to enter your prototype at the top of the program and donโt forget to insert the correct function call into the main function. Store the value returned by the function maxTemp() in the variable "maximum" so that it gets printed out properly in the following line.
Compile and run the code below in your own C environment.
#include <stdio.h>
#define NROWS 2 /* number of rows */
#define NCOLS 3 /* number of columns */
/* Don't forget your prototype! */
int main(void) {
/* Feel free to change the array, just be sure to update NROWS and NCOLS, if necessary. */
int temperature[NROWS][NCOLS] = {12, 56, 88, 34, 8, -3};
int maximum;
/* Function call here. */
printf("The maximal temperature is %d.", maximum);
return(0);
}
int maxTemp(int array[][NCOLS])
{
int max;
/* Your code here to find the maximum in array. */
/* Be sure to declare any needed additional variables. */
return(max);
}
When your program performs correctly youโll be given a keyword to enter in Canvas.
If your code appears to perform correctly but you are not given a keyword, please check for any extra spaces or line breaks in your output and remove them.
Compile and run the code below in your own C environment.
#include <stdio.h>
typedef struct {
char name[30];
long id;
int class;
} student_t;
int main(void)
{
student_t me = {"Petra", 123456L, 1994};
/* Complete the code in each of the three
lines below so that the student's record
is printed to the screen. */
printf("Student %s ",);
printf("with id %ld ", );
printf("belongs to the class of %d.", );
return(0);
}
Letโs continue developing the previous problem. This time weโll practice how to change entries in a structure. Complete the following C program so that the user can enter a new student name, id and class year to be stored in the variable me of type student_t. All you need to do is complete the scanf() and printf() lines.
Compile and run the code below in your own C environment.
#include <stdio.h>
typedef struct {
char name[30];
long id;
int class;
} student_t;
int main(void)
{
student_t me = {"Petra", 123456L, 1994};
/* Complete the commands to have the user enter a new
student name, id and class year: */
printf("Name: ");
scanf("%s", );
printf("id: ");
scanf("%ld", );
printf("class: ");
scanf("%d", );
/* Test whether the input worked: */
printf("Student %s ", );
printf("with id %ld ", );
printf("belongs to the class of %d.", );
return(0);
}
When your program performs correctly youโll be given a keyword to enter in Canvas.
If your code appears to perform correctly but you are not given a keyword, please check for any extra spaces or line breaks in your output and remove them.