1. ## problems with divison

Hi pals I am new in C programm but I have some problems with division in my simple code
thx
Code:
```#include<stdio.h>
#include<stdlib.h>
#include<math.h>
# define max 60
int main ()
{
float t[max],k,h,tmax;
int j,alpha,xmax,nstep,m;
printf("xmax\n");scanf("%d",&xmax);
printf("nstep\n");scanf("%d",&nstep);
tmax=0.5;
alpha=1;
/*xmax=1;*/
/*nstep=10;*/
h=xmax/nstep;
/*k=0.5*h*h/alpha;*/
k=0.5*h*h/alpha;
m=50;
for (j=0;j<=m;j++)
{ t[j]=j*k;
printf ("%d\t%1.3f\n",j,t[j]);
}
exit(0);
}```

2. Since xmax and nstep are integers, you are going to get an integer result. If nstep is greater than xmax, it is going to be zero, but for example nstep being 5 and xmax being 7 will give you 1 as a result, not 1.4.

The solutions available include (there are others, but that'll be more convoluted):
1. Cast xmax or nstep to float, e.g.
Code:
`   h = (float)xmax/nstep;`
2. Make xmax and/or nstep a floating point value rather than an integer.

--
Mats

3. Thanks Mats it works. I really appreciate your help. I am learning C because my supervisor asked me to learn it
Regards

4. Originally Posted by vikingcarioca
I am learning C because my supervisor asked me to learn it
Regards
and believe me you'll love learning C