following files do not contain specific record of data/lines or sential signal 1
ID: 1846831 • Letter: F
Question
following files do not contain specific record of data/lines or sential signal
1. Read the data file"diamond.txt" using a while loop and then print the values. the first column of the file contains carat weights and the second column refers to the corresponding prices.
2. Modify the code of problem 1 such that if two or more consecutive rows of data have the same carat weights the code will print the first row values for that weight and skip displaying the following row values for that weight.
3. Read the data file "corolla.txt" using a while loop and then print those in two columns (right alined). The first column of the file is the ages (how old the car is) of toyota corolla cars and the second column refers to the average prices asked by the sellers. 2. Read the data file "diamond.txt" using a while loop and then print the values. The first column of the file contains carat weights and the second column refers to the corresponding prices
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp;
fp=fopen("diamond.txt","r");
float temp;
int count;
count=0;
while (!feof (fp) && fscanf (fp, "%f ", &temp) )
{
if(count%2==0)
printf(" ");
count++;
printf("%f ",temp);
}
fclose(fp);
}
part 2:
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp;
fp=fopen("sensor2.txt","r");
float temp;
int count;
count=0;
float weight=0.0;
float temp1;
while (!feof (fp) && fscanf (fp, "%f %f ", &temp,&temp1) )
{
if(temp1==weight)
continue;
else
{
printf(" %f %f ",temp,temp1);
weight=temp1;
}
}
fclose(fp);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.