Thanks for the help!
So after reading all the replies I got something like this:
Code:
#include <stdio.h>
int main()
{
int c,n,a,calc,sum=0,x,i,final_a;
while((c = getchar()) != EOF)
{
sum = 0;
scanf("%d",&n);
scanf("%d",&a);
final_a = a;
calc = 0;
for(i=1; i<=n; i++)
{
for(x=1;x<i;x++)
{
final_a = final_a * a;
}
calc = i * final_a;
sum = sum + calc;
}
printf("N:%d A:%d\n",n,a);
printf("%d\n",sum);
}
}
So in the future; should I always declare ALL variables(int) before any loops? And only set them to 0 when I need to reset them?
Thanks