Ciao,
This is a function to find sum of squared number between [a,b] interval. So my question is how do i get an output if i dont declare acc and bcc. Of course the output is wrong but, shouldnt compiler give an error? Or what is the value of an undeclared variable?
Code:
#include <stdio.h>
int main (void) {
int a,b,ac,acc,bc,bcc;
int result;
scanf("%d%d",&a,&b);
acc=0;
bcc=0;
if(a<=100 && b<=100){
for(ac=1; ac<=a-1; ac++){
acc+=ac*ac;
}
for(bc=1;bc<=b; bc++){
bcc+=bc*bc;
}
}
result=bcc-acc;
printf("%d",result);
return 0;
}
Code:
#include <stdio.h>
int main (void) {
int a,b,ac,acc,bc,bcc;
int result;
scanf("%d%d",&a,&b);
if(a<=100 && b<=100){
for(ac=1; ac<=a-1; ac++){
acc+=ac*ac;
}
for(bc=1;bc<=b; bc++){
bcc+=bc*bc;
}
}
result=bcc-acc;
printf("%d",result);
return 0;
}