Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- float mean(float *x, int n);
- float summation(float *x, int n);
- float summation2(float *x, float *y, int n);
- void estimate(float intercept, float slope);
- int getN();
- int main() {
- int n = getN(); //number of programs
- float x[n] = 0; //estimated LOC for program n
- float y[n] = 0; //actual LOC for program n
- float sumX = 0;
- float sumY = 0;
- float sumXX = 0;
- float sumXY = 0;
- float slope = 0;
- float intercept = 0;
- //get the x and y
- int i = 0;
- for(i=0; i<n; i++) {
- printf("Input estimated LOC for program %d: ", i+1);
- scanf("%f", x[i]);
- printf("Input actual LOC for program %d: ", i+1);
- scanf("%f", y[i]);
- }
- //calculation
- //summation(x, n);
- /* calculate summations (summation)
- * calculate x*y summations (summation2)
- */
- slope = ((n*sumXY) - (sumX*sumY)) / ((n*sumXX)-(sumX*sumX));
- intercept = ((sumY - (slope*sumX)) / n);
- printf("Regression equation is:\n y = %f +%fx", intercept, slope);
- //ask user for programs to estimate
- //make a new function for that
- //continue to work until user types exit
- printf("Exiting program. Press any key to continue.");
- getch();
- }
- float mean(float *x, int n) {
- float result = 0;
- int i = 0;
- for(i=0; i<n; i++) {
- result = result + x[i]
- }
- result = result/n;
- return result;
- }
- float summation(float *x, int n) {
- float result = 0;
- int i = 0;
- for(i=0; i<n; i++) {
- result = result + x[i];
- }
- return result;
- }
- float summation2(float *x, float *y, int n){
- float result = 0;
- int i = 0;
- for(i=0; i<n; i++) {
- result = result + x[i]*y[i];
- }
- return result;
- }
- float estimate(float intercept, float slope) {
- int exit = 0;
- while() {
- printf("");
- //compute
- }
- }
- int getN() {
- int x = 0;
- printf("Input number of programs: ");
- scanf("%d", &x);
- return x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement