C programming >> help please! 2. Create a struct TempData which has an integer r
ID: 3764081 • Letter: C
Question
C programming >> help please!
2. Create a struct TempData which has an integer representing time and a double field representing temperature.
3. Create a function that takes an array of TempData, the size of the array and an integer variable num as arguments. The function should return the array index for the time num (index number of the array element that contains the value num in the time field).
4. Your program should read in the data from the input file into an array of TempData of size 50.
5. Your program prints out the time field for the first and last data points.
6. Then, your program asks the user for two numbers: the lower limit of the desired time interval and upper limit of the time interval, separated by a comma.
Explanation / Answer
Hello Kindly find the code attached for the program mentioned.
#include <stdio.h>
struct tempData {
int time;
double temp;
};
int getIndex(struct tempData tempArray[],int size,int num){
for(int i=0;i<size;i++){
if(tempArray[i].time==num)
{
return i;
}
}
return -1;
}
int main(void) {
struct tempData tempArray[2];
int num;
printf("Enter TempData1 Time :");
scanf("%d",&tempArray[0].time);
printf("Enter TempData2 Time :");
scanf("%d",&tempArray[1].time);
printf("Enter number to search: ");
scanf("%d",&num);
printf("%d",getIndex(tempArray,2,num));
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.