#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i = 10;
float f = 5.5;
double d = 6.6;
char c = 'a';
short s = 20;
long l = 30;
printf("int - float, %d - %g = %g\n",i,f,i-f);
printf("int + double, %d + %g = %g\n",i,f,i+f);
printf("int * double, %d * %g = %g\n",i,f,i*f);
printf("int / double, %d / %g = %g\n\n",i,f,i/f);
printf("int - double, %d - %g = %g\n",i,d,i-d);
printf("int + double, %d + %g = %g\n",i,d,i+d);
printf("int * double, %d * %g = %g\n",i,d,i*d);
printf("int / double, %d / %g = %g\n",i,d,i/d);
return 0;
}
결과
int - float, 10 - 5.5 = 4.5
int + double, 10 + 5.5 = 15.5
int * double, 10 * 5.5 = 55
int / double, 10 / 5.5 = 1.81818
int - double, 10 - 6.6 = 3.4
int + double, 10 + 6.6 = 16.6
int * double, 10 * 6.6 = 66
int / double, 10 / 6.6 = 1.51515
정수와 소수의 연산의 결과는 소수...이걸 만약에 쓸때 그대로 쓸지
(int) 같이 형변환해서 쓸지..잘 해라
'컴퓨터 과학 & 영상처리 관련 > C / C++' 카테고리의 다른 글
STL map 자료구조 (0) | 2012.10.11 |
---|---|
c++ STL sort 함수 (0) | 2012.10.11 |
devcpp getchar();getchar(); 대신 system("pause"); 가능 (0) | 2012.09.03 |
static이용 함수 내에서 포인터 반환 (0) | 2012.09.03 |
배열 포인터를 이용한 2차원 배열을 함수 인자로 주기.. (0) | 2012.09.03 |