Note that there are some explanatory texts on larger screens.

plurals
  1. POC run-time error for a program to sum polynomials
    primarykey
    data
    text
    <p>This program is for adding two polynomials and printing the result.</p> <p>It just stores the multipliers in array and use the index az the power of parameter </p> <p>It does sum and subtract but when it comes to product it prints </p> <pre><code>0x0 0*x2 0*x3 ... </code></pre> <p>It's for basic C programming class and in three hours I should give it to master :-(</p> <p>It gets the multiplier in an array and calculates the result using some functions:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; double a[50], b[50], c[101]; int dega, degb; SumArray (a, b) double a[], b[]; { extern int dega, degb; extern double c[]; int i, max = (dega &lt; degb ? degb : dega) + 1; for(i = 0; i &lt; max; i++) c[i] = a[i] + b[i]; } SubtractArray(a, b) double a[], b[]; { extern int dega, degb; extern double c[]; int i, max = (dega &lt; degb ? degb : dega) + 1; for (i = 0; i &lt; max; i++) c[i]=a[i]-b[i]; } ProductArray(a, b) double a[], b[]; { extern int dega, degb; extern double c[]; int i,j; double tempa, tempb; for(i = 0; i &lt; dega + 1; i++) for(j = 0; j &lt; degb + 1; j++) { tempa = a[i]; tempb = b[j]; c[i + j] = c[i + j] + (tempa * tempb); } } int main() { extern int dega, degb; extern double a[50], b[50], c[]; //stores the multipliers int i, operation; for(i = 0; i &lt; 50; i++) a[i] = b[i] = 0; for(i = 0; i &lt; 102; i++) c[i] = 0; printf("darjeye chand jomleee ha ra vared konid"); scanf("%d %d", &amp;dega, &amp;degb); printf("zarayebe chand jomlee aval ra vaerd konid"); for(i = 0; i &lt; dega + 1; i++) scanf("%d", &amp;a[i]); printf("zarayebe chand jomlee dovoom ra vaerd konid"); for(i = 0; i &lt; degb + 1; i++) scanf("%d", &amp;b[i]); printf("amaliyate morede nazartan ra vare konid baraye jame 0, tafrigh 1, zarb 2 ra vared konid"); scanf("%d", &amp;operation); switch(operation) { case 0: { SumArray(a,b); for (i = 0; i &lt; (dega &gt; degb ? dega : degb) + 1; i++) { printf(" %d*x", c[i]); printf("%d ", i); } break; } case 1: { SubtractArray(a,b); for (i = 0; i &lt; (dega &gt; degb ? dega : degb) + 1; i++) { printf(" %d*x", c[i]); printf("%d ", i); } break; } case 2: { ProductArray(a,b); for(i = 0; i &lt; (dega + degb + 1); i++) { printf("\%d*x", c[i]); printf("%d ", i); } break; } default: printf("amaliyate vared shode sahih nabud"); } system("PAUSE"); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload