jins coding sample blog

10월 28일 본문

C 응용/우분투 c

10월 28일

jins code 2019. 10. 28. 18:26

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;

밑으로 5~9단까지 같은 방법으로 출력됨

 

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;

 

}

 

-1 음수 -> +1 양수 로 바뀐 화면

 

3. 사각형의 넓이

#include <stdio.h>

int main ()

{

int x, y ;

printf("두 정수를 입력하면 넓이 값이 나옵니다.\n");

scanf("%d %d", &x, &y);

 

printf("넓이 값은 %d 입니다.", x*y);

 

}

 

한 변이 각각 +4, +5 인 사각형의 넓이 값.  

 

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;

정수 1,2,3,4 를 넣고, 평균값 2.5가 나온 화면

 

'C 응용 > 우분투 c' 카테고리의 다른 글

11월 06일  (0) 2019.11.06
10월 31일  (0) 2019.10.31
10월 30일  (0) 2019.10.30