can someone tell me what am i doing wrong with for loop. its not returning what its suppose to. everything else works except for that.
Code:#include <stdio.h> int min(); int max(); main() { double x[10], y[10], z[19]; int c; int f; FILE *inp; int input_status; int i,t; double a,b; inp = fopen("input-xy.txt", "r"); //opens files input_status = fscanf(inp, "%d %lf %lf", &i,&a,&b); //takes digits while(input_status != EOF) { x[i]=a; y[i]=b; input_status = fscanf(inp, "%d %lf %lf", &i,&a,&b); } fclose(inp); for(t=1;t<=6;t++) printf("%lf %lf\n",x[t],y[t]); int j,q; double sum; for(j=0; j<=18; ++j) { c = max(j); //cant figure out whats wrong with it f= min(j); sum=1; for(c;c<=f;c++) { q=x[c]*y[j-c]; sum= sum + q; } z[j]=sum; printf("z[%d]= %lf\n",j,z[j]); } system("pause"); } int min(int j) { int min; if(9>=j) min=j; else if(9<=j) min=9; return min; } int max(int j) { int max; if((9-j)<=j) max=j; else if((9-j)>=j) max=(9-j); return max; }



LinkBack URL
About LinkBacks


