int
형 대신 long
형 변수를 사용하는 이유는 무엇인가?int
의 한계(limit
) 를 뛰어넘는 데이터 처리에 대한 확장성과 이식성을 확보하기 위해서.
int32_t
: int32_t
자료형은 C 표준에서 반드시 32
비트임을 보장하기 때문이다.
#include <stdio.h>
int main(void)
{
float g, h;
float tax, rate;
rate = 1.04;
g = 1.0e21;
tax = rate * g;
printf("tax: %f\n", tax);
return 0;
}
#include <stdio.h>
int main(void)
{
int imate = 2;
long shot = 53456;
char grade = 'A';
float log = 2.71828;
printf("%d 등에 당첨될 확률은 %ld 분의 1이다.\n", imate, shot);
printf("%f 의 성적은 %c 학점이다.\n", log, grade);
return 0;
}
#include <stdio.h>
int main(void)
{
char ch;
ch = 13;
ch = '\r';
ch = '\013';
ch = '\x0D';
return 0;
}
#include <stdio.h>
int main(void)
{
int cows, legs, integer;
printf("젖소들의 다리를 세어 보니 모두 몇 개더냐? \n");
scanf("%d", &legs);
cows = legs / 4;
printf("그렇다면 젖소가 %d 마리로구나.\n", cows);
return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
int main(void)
{
int32_t a, b, c;
float flt;
double dlb;
a = 0xFFFFFFFF; b = 1;
c = a + b;
flt = 1.0E+50;
dlb = 512.1266E-326;
printf("%" PRId32 "\n", c);
printf("%f\n", flt);
printf("%.400f\n", dlb);
return 0;
}
#include <stdio.h>
int main(void)
{
int chr;
scanf("%d", &chr);
printf("%c", chr);
return 0;
}
#include <stdio.h>
int main(void)
{
printf("\a갑작스런 소리에 깜짝 놀라 샐리는 외쳤다,\n"
"\"호박대왕이다!\"\n");
return 0;
}
#include <stdio.h>
int main(void)
{
double flt;
scanf("%lf", &flt);
printf("고정소수점 표기: %f\n", flt);
printf("지수 표기: %e\n", flt);
printf("p 표기: %a\n", flt);
return 0;
}
#include <stdio.h>
int main(void)
{
int year;
long double seconds;
printf("Enter the year: "); scanf("%d", &year);
seconds = year * (3.156e+7);
printf("years to seconds: %Lg\n", seconds);
return 0;
}
#include <stdio.h>
int main(void)
{
const double gram_for_O2 = 3.0e-23;
double gram;
int quart;
printf("Enter the quart: "); scanf("%d", &quart);
gram = quart * 950;
printf("quater to molecule: %f\n", gram / gram_for_O2);
return 0;
}
#include <stdio.h>
int main(void)
{
double inch, centi;
printf("Enter the your height (centi): ");
scanf("%lf", ¢i);
printf("centimeter to inch: %f\n", centi / 2.54);
return 0;
}
#include <stdio.h>
int main(void)
{
float pints;
int cups, ounces, tablespoons, teaspoons;
printf("cups: "); scanf("%d", &cups);
pints = cups / 2.0f;
ounces = cups * 8;
tablespoons = ounces * 2;
teaspoons = tablespoons * 3;
printf("pints: %f\n", pints);
printf("cups: %d\n", cups);
printf("ounces: %d\n", ounces);
printf("tablespoons: %d\n", tablespoons);
printf("teaspoons: %d\n", teaspoons);
return 0;
}
pints
를 제외한 모든 단위들이 cups
의 배수이므로