본문 바로가기
728x90

c examples8

[C++ Examples/Arduino] Digital Inputs and If Statements 예제코드 및 설명 Digital Inputs by Using Led and Buttons (If Statements) 예제코드 및 설명 포스트 난이도: HOO_Junior # Example Code int ledPin = 5; int buttonApin = 9; int buttonBpin = 8; //byte leds = 0; void setup() { // put your setup code here, to run once: pinMode(ledPin, OUTPUT); pinMode(buttonApin, INPUT_PULLUP); pinMode(buttonBpin, INPUT_PULLUP); } void loop() { // put your main code here, to run repeatedly: if (digit.. 2024. 1. 15.
[C Examples] do while문을 사용해서 섭씨를 화씨로 변환하기 do while문을 사용해서 섭씨를 화씨로 변환하기 포스트 난이도: HOO_Intern # Example Codes 이번 예제코드를 통해서 섭씨를 화씨로 산출되는 걸 확인할 수 있다. 이번 코드에서는 do while문을 어떤 식으로 사용되고 있는지를 살펴볼 수 있다. do while문을 사용하지 않더라도 섭씨를 화씨로 계산하는 식을 작성함으로써 화씨 값이 산출이 되지만 do while문을 통해서 섭씨가 영하로 나오는 값이 계산이 안되게끔 설정이 가능하다. 예를 들어서 아래의 코드를 살펴보면, celsius 값이 0보다 작을 경우 다시 0보다 큰 값을 작성하도록 코드가 구성되어 있는 걸 볼 수 있다. 이처럼 do while문을 통해서 원하는 산출 값을 얻기 위한 반복적인 작업이 가능하다. #include .. 2023. 9. 3.
[C Examples] 알파벳 모음, 자음 구분하기 예제코드: switch() 알파벳 모음, 자음 구분하기 예제코드: switch() 포스트 난이도: HOO_Junior # Example Codes #include #include int main() { char ch; printf("Enter any alphabet:"); //input alphabet from user scanf("%c", &ch); switch(ch){ case 'A': printf("Vowel\n"); break; case 'E': printf("Vowel\n"); break; case 'I': printf("Vowel\n"); break; case 'U': printf("Vowel\n"); break; case 'O': printf("Vowel\n"); break; case 'a': printf("Vowel.. 2023. 3. 24.
[C Examples] 입력된 숫자의 각 자리수를 더하고 3과 9로 나누어지는지 살펴보는 예제코드: do while(), if() 입력된 숫자의 각 자리수를 더하고 3과 9로 나누어지는지 살펴보는 예제코드: do while(), if() 포스트 난이도: HOO_Junior # Example Codes #include int main() { int num, digit, sum=0; printf("Enter a positive integer: "); scanf("%d", &num); do { digit = num % 10; sum += digit; num /= 10; } while (num != 0); printf("The sum of the digits = %d\n", sum); num = sum; do { num -= 3; } while (num >= 3); if (num == 0) { printf("%d is divisible b.. 2023. 3. 23.
[C Examples] 입력한 온도 값에 따라 온도 상태 구분하기 예제 코드: if(), else if(), while() 입력한 온도 값에 따라 온도 상태 구분하기 예제 코드: if(), else if(), while() 포스트 난이도: HOO_Junior # Example codes #include int main(){ int temperature[50]; int n,i,hot=0,pleasant=0,cold=0; float average=0; printf("Enter number of temperatures:"); scanf("%d",&n); printf("Enter Temperatures: "); while(i=60&&temperature[i] 2023. 3. 22.
[C Examples] 세금 계산기 예제코드: if, else if 세금 계산기 예제코드: if, else if 포스트 난이도: HOO_Intern # Example Codes #include #include int main() { float salary,tax; tax = 0; printf("Income: $"); scanf("%f",&salary); if (salary < 1000) { tax = 0.01 * salary; } else if (salary < 2000) { salary=salary-1000; tax = 0.01 * salary; tax = tax + 10; } else if (salary 2023. 2. 19.
[C Examples] 24시간을 12시간 표기로 바꾸기 예제코드: if(), else 24시간을 12시간 표기로 바꾸기 예제코드: if(), else 포스트 난이도: HOO_Intern # Example Codes #include #include int main() { int userHour, userMinute, hour; printf("Time(e.g., 23:15):"); scanf("%d:%d", &userHour, &userMinute); if (userHour > 11) { hour = userHour - 12; if(hour == 12){ printf("Time is 00:%d AM\n", userMinute); } else{ printf("Time is %d:%d PM\n", hour, userMinute); } } else{ printf("Time is %d:%d AM\n.. 2023. 2. 18.
[C Examples] 7 Digit ISSN, 8번째 숫자 산출하기 예제코드: if(), else(), %d 7 Digit ISSN, 8번째 숫자 산출하기 예제코드: if(), else(), %d 포스트 난이도: HOO_Junior # Example Codes #include int main() { int frontISSN, frontISSNOne, frontISSNTwo, frontISSNThree, frontISSNFour, backISSN, backISSNOne, backISSNTwo, backISSNThree, backISSNPer, modNum, unknownNum; printf("Enter the 7 digit ISSN in form of XXXX-XXX:"); scanf("%d - %d", &frontISSN, &backISSN); frontISSNOne = frontISSN/1000; frontI.. 2023. 2. 15.
728x90