| | |
finding the highest value help
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2004
Posts: 573
Reputation:
Solved Threads: 5
Hi,
I am new to programming. The program I made reads a list of points from a text file. Then it finds the standard deviation and how many sets of points are in the file. Now I want to find the highest x value from the list and the highest y value from the list. So far I made the variables for these two values and I know I have to use an if statement.
Here is the code:
Thank You
I am new to programming. The program I made reads a list of points from a text file. Then it finds the standard deviation and how many sets of points are in the file. Now I want to find the highest x value from the list and the highest y value from the list. So far I made the variables for these two values and I know I have to use an if statement.
Here is the code:
C Syntax (Toggle Plain Text)
#include<stdio.h> #include<math.h> int main(int argc, char *argv[]) { FILE *input; float x, y, sumx, sumy, avex, avey, sumx_sqrd, sumy_sqrd, xmax, ymax; int count; if (argc == 1) { fprintf(stderr, "You must supply a file name.\n"); return 1; } input = fopen(argv[1], "r"); if (input == NULL) { fprintf(stderr, "Error opening file \"%s\".\n", argv[1]); return 1; } sumx = 0.0; sumy = 0.0; sumx_sqrd = 0.0; sumy_sqrd = 0.0; count = 0; while (fscanf(input, "%f\t%f", &x, &y) != EOF) { count++; sumx += x; sumy += y; sumx_sqrd += x * x; sumy_sqrd += y * y; } fclose(input); avex = sumx/count; avey = sumy/count; printf("Average of x = %f\n", avex); printf("Standard deviation of x = %f\n", sqrt(sumy_sqrd/count - avex * avex)); printf("\n"); printf("Average of y = %f\n", avey); printf("Standard deviation of y = %f\n", sqrt(sumy_sqrd/count - avey * avey)); printf("\n"); printf("The maximum x value is %f\n", ); printf("The maximum y value is %f\n", ); printf("\n"); printf("The number of data sets is %d\n", count); return 0; }
Thank You
Last edited by alc6379; Nov 8th, 2004 at 3:42 am. Reason: added [code] tags
![]() |
Similar Threads
- finding mode (C++)
- What to fetch second highest marks? (MySQL)
- Error in output (C)
- The following Code won't work, Plez help? (C++)
- finding max value of 10 integers (C++)
- Looking up and displaying values in linked lists (C++)
- Outputting data (C++)
Other Threads in the C Forum
- Previous Thread: limitations of 10 employees per page
- Next Thread: Exiting your program?
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opensource overwrite owf pdf performance pointer posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi





