i have this code
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int a[10],h=0;
a[1]=1;
a[2]=0;
a[3]=2;
a[4]=5;
for(int i=1; i<=4; i++){
cout<<h<<" + "<<pow(a[i],2)<<" = ";
h = h + ((int)pow(a[i],2));
cout<<h<<"\n";
}
cout<<"h = "<<h;
}
and the result will be like this
0 + 1 = 1
1 + 0 = 1
1 + 4 = 5
5 + 25 = 29
h = 29
but when we change variable to double we would get the right answer. so, can someone explain to me why we get that answer wen we use int ?