jins coding sample blog
10월 28일 본문
1. for 문을 이용한 구구단 작성
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
int x, y ;
for (x=1; x<=9; x++)
{
for (y=1; y<=9; y++)
}
{
printf("%d * %d = %d", x, y, x*y);
}
return 0;
}
2. 가정문을 이용하여, 양수를 음수로 전환
#include <stdio.h>
int main ()
{
int x ;
printf("음수를 입력하면, 양수로 바뀝니다. \n", x);
scanf("%d", &x);
int y = x*(-1);
printf("양수로 바꾼 값은 %d 입니다. \n"), y);
scanf("%d", %y);
return 0;
}
3. 사각형의 넓이
#include <stdio.h>
int main ()
{
int x, y ;
printf("두 정수를 입력하면 넓이 값이 나옵니다.\n");
scanf("%d %d", &x, &y);
printf("넓이 값은 %d 입니다.", x*y);
}
4. 네 정수의 합산 구하기
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main ()
{
int w,x,y,z,sum;
double avg = 0.0 ;
printf("네 정수를 입력하면, 평균 값이 나옵니다. \n");
scanf("%d %d %d %d", &w, &x, &y, &z);
sum = w+x+y+z ;
avg = sum / 4.0 ;
printf("평균값은 %.1lf 입니다. \n", avg);
return 0;
}