i cannot figure out how to input the square root of this problem. i just started a class a few days ago at university and my teacher made the assumption that we all have a hale background in computer science:
To test our knowledge of loops and if statements, we shall write a program which will prompt the user to enter an integer n. If n is positive, the user should print out a table of squares, cubes and square roots of the numbers between 1and n (inclusive). If the number is zero or negative, the user should print an appropriate error message.
i've had to largely teach myself with online courses, so i've been hacking away at this for a few hours. it must be noted again that i am a complete novice, so please be liberal with the layman's terms.
this is what i've got so far:
#include <stdio.h>
#include <math.h>
int main(void)
{
int n;
int r=(n-1);
printf("Enter an Integer: ");
scanf("%d", &n);
if (n>0)
{
printf("%d\n",n*n*n);
printf("%d\n",n*n);
printf("%f\n",sqrt(n));
}
while (r>1)
{
printf("%d",r);
r=r*r*r;
r=r*r;
printf("%f",r=sqrt(r));
}
else
{
printf("Sorry, try inputting a positive number next time.\n");
}
return 0;
}
thanks in advance for being reasonable.