ETC๐Ÿงท

(์—ดํ˜ˆ C ํ”„๋กœ๊ทธ๋ž˜๋ฐ) ์—ฐ์Šต๋ฌธ์ œ ํ’€์ด chapter-07(2)

hae02y 2019. 12. 15. 17:33
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ 07-2

 

1. 5๊ฐœ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ํ•ฉ์„ ๊ตฌํ•œ๋‹ค. ์ •์ˆ˜๋Š” ๋ฐ˜๋“œ์‹œ 1์ด์ƒ์ด๊ณ  1๋ฏธ๋งŒ์ผ ๊ฒฝ์šฐ ์žฌ์ž…๋ ฅ์„ ์š”๊ตฌํ•œ๋‹ค.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<stdio.h>
 
int main()
{    
    int i = 0;
    int a;
    int result = 0;
    while(i<5)
    {    
        bb:
        printf("%d ๋ฒˆ์งธ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : ",i+1);
        scanf("%d",&a);
    
        if(a < 1)
        {
            printf("์žฌ์ž…๋ ฅํ•˜์„ธ์š”\n");
            goto bb;
        }
        result += a;
        i++;
    }
    printf("์ดํ•ฉ์€ %d ์ž…๋‹ˆ๋‹ค.",result);
}
cs

//goto๋ฌธ์„ ์‚ฌ์šฉํ•จ

 

 

2. ์•„๋ž˜ ์ถœ๋ ฅ์„ ๋ณด์ด๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑ 5ํ–‰์— ๊ฑธ์ณ ์ถœ๋ ฅ์„ ํ•˜๊ณ  ํ–‰์ด ๋”ํ•ด์ง€๋ฉด 0๋ฌธ์ž๊ฐ€ ์ฆ๊ฐ€ํ•จ.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
 
int main()
{    
    int i = 0;
    int j = 0;
    while(i<5)
    {    
        while(j<i)
        {
            printf("0");
            j++;
        }
        printf("* \n");
        j = 0;
        i++
    }
}
cs

 

 

 

๋ฐ˜์‘ํ˜•