본문 바로가기

Coding/문제풀이 중심의 C언어 연습

문제풀이 중심의 C언어 연습 2장 실습문제

문제 2-1

#include <stdio.h>

int main(){
	int a = 20, b = -5;
	printf("%d + %d = %d", a, b, a + b);
}

 

문제 2-2

#include <stdio.h>

int main(){
	float ave = 10.25, sum = 4.32;
	printf("%.2f + %.2f = %.2f\n", ave, sum, ave + sum);
	printf("%.2f - %.2f = %.2f", ave, sum, ave - sum);
}

 

문제 2-3

#include <stdio.h>

int main(){
	int no = 40000, count = 13000;
    printf("%d + %d = %d", no, count, no + count);
}

 

문제 2-4

#include <stdio.h>

int main(){
	float no = 12, ave = 324.1234;
	printf("%.f + %4f = %.4f", no, ave, no + ave);
}

 

문제 2-5

#include <stdio.h>

int main(){
	char ch = 'A';
	printf("%c의 ASCII 값은 %d입니다.", ch, ch);
}

 

문제 2-6

#include <stdio.h>

int main(){
	int val = 97;
	printf("ASCII값 %d의 영문자는 %c입니다." val, val);
}

 

문제 2-7

#include <stdio.h>

int main(){
	printf("char	: %d byte\n", sizeof(char));
	printf("short	: %d byte\n", sizeof(short));
	printf("int	: %d byte\n", sizeof(int));
	printf("long	: %d byte\n", sizeof(long));
	printf("float	: %d byte\n", sizeof(float));
	printf("double	: %d byte\n", sizeof(double));
}