#include <stdio.h>
#include <stdlib.h>
int main()
{
int val1=10;
int val2=4;
int result1=0;
int result2=0;
int result3=0;
double result4=0;
printf("%d\n",result1=val1+val2);//整數+整數
printf("%d\n",result2=val1-val2);//整數-整數
printf("%d\n",result3=val1*val2);//整數*整數
printf("%f\n",result4=(double)val1/(double)val2);//整數除整數是整數在assign result
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int val1=10;
float val2=4;
float result1=0;
float result2=0;
float result3=0;
float result4=0;
printf("%d\n",result1=val1+val2);//整數+整數
printf("%d\n",result2=val1-val2);//整數-整數
printf("%d\n",result3=val1*val2);//整數*整數
printf("%f\n",result4=val1/val2);//整數除整數是整數在assign result
//其被加數、或被減數、被乘數、被除數只要其中設一個float即可,但+ - * 會有問題
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int val1=10;
int val2=4;
int result1=0;
int result2=0;
int result3=0;
float result4=0;
printf("%d\n",result1=val1+val2);//整數+整數
printf("%d\n",result2=val1-val2);//整數-整數
printf("%d\n",result3=val1*val2);//整數*整數
printf("%f\n",result4=(float)val1/(float)val2);//整數除整數是整數在assign result
return 0;
}
沒有留言:
張貼留言