#include <stdio.h>
int main ()
{
int a;
a = -29;
if (a*a*a+a*a-905*a-2697==0)
printf("%d is a root of the given polynomial.\n",a);
a = 31;
if (a*a*a+a*a-905*a-2697==0)
printf("%d is a root of the given polynomial.\n",a);
printf("The third root of the given polynomial is %d.\n", -1 - (-29 + 31));
}
#include <stdio.h>
int main ()
{
int a = -2931;
if (a*(a*a+2871*a-174961)+2634969==0)
printf("%d is a root of the given polynomial.\n",a);
}
#include <stdio.h>
int main ()
{
int r, nroot = 0;
for (r=1; nroot<3; r++) {
if (5294016 % r == 0) {
if (r*r*r+r*r-74034*r+5294016==0) {
printf("Root found : %d\n",r);
nroot++;
}
if (-r*r*r+r*r+74034*r+5294016==0) {
printf("Root found : %d\n",-r);
nroot++;
}
}
}
}
The output of this program is
Root found : 78 Root found : 224 Root found : -303
f(r)=0, f'(r)=0, ..., f(k-1)(r)=0, f(k)(r)!=0.For a cubic polynomial a root can have a maximum multiplicity of 3. So it is sufficient to consider upto the second derivative.
#include <stdio.h>
int main ()
{
int r, nroot = 0;
for (r=1; nroot<3; r++) {
if (1815937 % r == 0) { /* The root must divide the constant term */
if (r*r*r+r*r-28033*r-1815937==0) { /* Evaluate f(r) */
printf("Root found : %d\n",r);
nroot++;
if (3*r*r+2*r-28033==0) { /* Evaluate f'(r) */
printf("Root found : %d\n",r);
nroot++;
if (6*r+2==0) { /* Evaluate f''(r) */
printf("Root found : %d\n",r);
nroot++;
}
}
}
if (-r*r*r+r*r+28033*r-1815937==0) { /* Evaluate f(-r) */
printf("Root found : %d\n",-r);
nroot++;
if (3*r*r-2*r-28033==0) { /* Evaluate f'(-r) */
printf("Root found : %d\n",-r);
nroot++;
if (-6*r+2==0) { /* Evaluate f''(-r) */
printf("Root found : %d\n",-r);
nroot++;
}
}
}
}
}
}
The output of this program is:
Root found : -97 Root found : -97 Root found : 193
#include <stdio.h>
int main ()
{
double t=0, /* Time initialized to 0 */
dist=0, /* Distance traversed by the ant */
slen=10; /* Length of the string */
while (dist < slen) {
dist+=1; /* Ant's move in 1 second */
t+=1; /* Time increases by 1 second */
slen+=10; /* The string stretches */
dist*=(t+1)/t; /* Stretching helps the ant too! */
/* printf("After %d seconds: string length = %d cm, ant covered %f cm\n",
(int)t, (int)slen, dist); */
}
printf("Ant reached the right end in %d seconds!!!\n", (int)t);
}
The answer is 12367 seconds.
[Course home] [Home]