Code for PROGRAM SHOWING THE USE OF A CAST in C Programming
main()
{
float sum ;
int n ;
sum = 0 ;
for( n = 1 ; n <= 10 ; ++n )
{
sum = sum + 1/(float)n ;
printf("%2d %6.4f\n", n, sum) ;
}
}
Output
1 1.0000
2 1.5000
3 1.8333
4 2.0833
5 2.2833
6 2.4500
7 2.5929
8 2.7179
9 2.8290
10 2.9290