Hi all,
I've just started to learn C language, I've completed several commands by myself and stuck at the code as under,
insert
Code:
#include <stdlib.h>
int main(){
int array[]={1,2,3,4,5};
int factorial =1;
int i;
for(i=0;i<5;i++)
factorial*=array[i];
printf("5! is %d.\n", factorial);
return 0;
}
the above code works perfectly, but whenever i tried to change %d to %f it gives me an error.
also in the code under,
Code:
#include <stdlib.h>
int main(){
int a=1;
float b=1.2;
double c =1.21;
float sum;
sum =a+b+c;
printf("Sum of 3 values is%f",sum);
return 0;
}
Whenever i tried to put %d in place of %f it gives me an error. (I've attached the error screen shot)
kindly help me understand why i need to put %f only and not any other alphabet?
thanks
- Hardip