3_7
// 시험 점수를 입력받아 다중 if문을 이용하여 학점을 구하는 프로그램 #include <stdio.h>
int main() { int score; char grade = 'X'; // grade를 미리 초기화한다. printf("Please enter examination score: "); scanf("%d", &score); if((score <= 100)&&(score >=90)) { grade = 'A'; } else if((score < 90)&&(score >= 80)) { grade = 'B'; } else if((score < 80)&&(score >= 70)) { grade = 'C'; } else if((score < 70)&&(score >= 60)) { grade = 'D'; } else if((score < 60)&&(score >= 0)) { grade = 'F'; } else { printf("wrong score\n"); } printf("The grade is %c\n", grade); return 0; } |
3_8
// 시험 점수를 입력받아 switch 문을 이용하여 학점을 구하는 프로그램 #include <stdio.h>
int main() { int score; char grade;
printf("Please enter examination score: "); scanf("%d", &score); score = score / 10; switch(score) { case 10 : case 9 : grade = 'A'; break; case 8 : grade = 'B'; break; case 7 : grade = 'C'; break; case 6 : grade = 'D'; break; default : grade = 'F'; break; } printf("The grade is %c\n", grade); return 0; }
|
3_9
/* 0에서 9까지 입력받아 영어로 출력하는 프로그램으로 switch 문의 정수값으로 문자형 변수를 사용한 예 */
#include <stdio.h>
int main() { char ch; printf("Please enter a number between 0 to 9 : "); scanf("%c", &ch); switch(ch) { case '0' : printf("Input Number is Zero.\n"); break; case '1' : printf("Input Number is One.\n"); break; case '2' : printf("Input Number is Two.\n"); break; case '3' : printf("Input Number is Three.\n"); break; case '4' : printf("Input Number is Four.\n"); break; case '5' : printf("Input Number is Five.\n"); break; case '6' : printf("Input Number is Six.\n"); break; case '7' : printf("Input Number is Seven.\n"); break; case '8' : printf("Input Number is Eight.\n"); break; case '9' : printf("Input Number is Nine.\n"); break; default : printf("wrong number.\n"); } return 0; }
3_10
/* getchar()/putchar() 함수를 이용하여 키보드로부터 한 문자를 입력받아 화면에 출력하는 프로그램 */
#include <stdio.h>
int main() { char ch;
printf("Please enter any character: "); ch = getchar(); // 문자입력 putchar (ch); // 문자출력 printf(" is a letter you typed.\n"); fflush(stdin); printf("Please enter any character: "); scanf("%c", &ch); printf("%c is a letter you typed.\n", ch); return 0; }
|
3_11
// getch(), getche(), putch() 함수를 이용한 문자 입출력 프로그램
#include <conio.h> // getche(), getch(), putch() 함수의 이용 #include <stdio.h> // printf() 함수의 이용
int main() { int ch; printf("Please enter any character: "); ch = getche(); putch(ch); printf(" is a letter you typed.\n"); printf("Please enter any character: \n"); ch = getch(); // 입력 문자는 화면에 출력되지 않음 putch(ch); printf(" is a letter you typed.\n"); return 0; }
|
3_12// while 문을 이용하여 화면에 0부터 5까지 출력하는 프로그램
#include <stdio.h>
int main() { int num; num = 0; // 제어변수 n의 초기화 while(num <= 5) // 반복여부를 결정하는 논리식 { printf("%d\t", num); num = num + 1; // 제어변수의 값의 변경 } printf("\n"); return 0; } |
test
#include <stdio.h>
int main() { putchar(51); //putchar 는 한글자를 아스키코드로 받는다. putchar('3'); putchar('\n'); return 0; }
| |
test1
#include <stdio.h>
int main() { printf("Hello~!\n"); getchar(); //엔터값이 남아있어 대기상태에 있는다 return 0; }
| |
test2
#include <stdio.h>
int main() { unsigned int uiCnt = 490; //while(500>=uiCnt) while(1) { if(uiCnt>500) { break; // 멈추는 방법을 잘 생각하여 보자. } printf("%dHEHEHEHE\n", uiCnt); ++uiCnt; } return 0; }
|
// 구구단 5단
test3
#include <stdio.h>
int main() { unsigned int uiCnt = 1; unsigned char ucdan = 5; /*printf("%d * 1 = %d\n", ucdan, ucdan*1); printf("%d * 2 = %d\n", ucdan, ucdan*2); printf("%d * 3 = %d\n", ucdan, ucdan*3); printf("%d * 4 = %d\n", ucdan, ucdan*4); printf("%d * 5 = %d\n", ucdan, ucdan*5); printf("%d * 6 = %d\n", ucdan, ucdan*6); printf("%d * 7 = %d\n", ucdan, ucdan*7); printf("%d * 8 = %d\n", ucdan, ucdan*8); printf("%d * 9 = %d\n", ucdan, ucdan*9);*/ while(uiCnt<10) { printf("%d * %d = %d\n", ucdan, uiCnt, ucdan*uiCnt); ++uiCnt; } return 0; }
| | |