1ST Programming
-
[c언어] Add Digits1ST Programming/C 2021. 1. 10. 20:05
4. Write a C program to calculate the sum of digits of a number: we will use modulus operator (%) to extract individual digits of a number and keep on adding them. #include #include int main() { int num; int length = 1; int cnt = 0; int t = 0; int sum = 0; printf("숫자를 입력하세요: "); scanf("%d",&num); while(1) { if(num%length == num) break; length *= 10; cnt++; } for(int i = 0; i < cnt; i++) { t = nu..
-
[c언어]Growing Plant1ST Programming/C 2021. 1. 10. 19:30
3. Caring for a plant can be hard work, but since you tend to it regularly, you have a plant that grows consistently. Each day, its height increases by a fixed amount represented by the integer upSpeed. But due to lack of sunlight, the plant decreases in height every night, by an amount represented by downSpeed. Since you grew the plant from a seed, it started at height 0 initially. Given an int..
-
[c언어] Circle of Numbers1ST Programming/C 2021. 1. 2. 08:33
2. Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighboring numbers is equal (note that 0 and n - 1 are neighboring, too). Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber. for example For n = 10 and firstNumber = 2, the output should be circleOfNumbers(n, firstNumb..
-
[c언어] 홀수 짝수 판별 Odd or Even1ST Programming/C 2021. 1. 2. 08:13
1. We will determine whether a number is odd or even by using different methods all are provided with a C language program. As you have studied in Mathematics that in decimal number system even numbers are divisible by two while odd numbers are not so we can use modulus operator(%) which returns remainder, for example, 4%3 gives 1 (remainder when four is divided by three). Even numbers are of th..