본문 바로가기

행복한 프로그래밍

(37)
fahr >> upper #include <stdio.h> main() { int fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; fahr = lower ; while (fahr <= upper){ celsius = 5 * (fahr-32) / 9; printf("%d\t%d\n", fahr, celsius); fahr = fahr + step; } }
chess #include <stdlib.h> int numcmp(char *s1, char *s2) { double v1, v2; v1 = atof(s1); v2 = atof(s2); if (v1 < v2) return -1; else if (v1 > v2) return 1; else return 0; } void swap(void *v[], int i, int j) { void *temp; temp = v[i]; v[i] = v[j]; v[j] = temp; }
factorial #include <stdio.h> main() { int number, factorial; printf("정수를 입력하시오: "); scanf("%d", &number); factorial = 1; while (number > 0){ factorial = factorial*number; --number; } printf("팩토리얼값(n!)=%d \n", factorial); return 0; }
ID의 원리 #include <stdio.h> main() { int ctr; int idSearch; int found = 0; int custID[10] = { 313, 453, 502, 101, 892, 475, 792, 912, 343, 633 }; float custBal[10] = { 0.00, 45.43, 71.23, 301.56, 9.08, 192.41, 389.00, 229.67, 18.31, 59.54 }; printf("\n\n*** 고객 카드 사용액 검색 ***\n"); printf("어떤 고객의 카드 사용액을 검색하시겠습니까? "); scanf(" %..
단순한 오타 #include <stdio.h> main(){ int value1; int value2; int quotient; int remainder; printf("첫 번째 정수: "); scanf("%d", &value1); printf("두 번째 정수: "); scanf("%d", &value2); quotient = value1 / value2; remainder = value1%value2; printf("\n몫은 %d입니다. \n", quotient); printf("나머지는 %d입니다. \n", remainder); return 0; } 이걸 프로그래밍..
합계를 구하는 프로그래밍 #include <stdio.h> main() { int sum = 0, num; do { printf("정수를 입력하시오:"); scanf("%d", &num); sum += num; } while (num != 0); printf("합계=%d", sum); return 0; }
컴퓨터의 계산 속도 (calculating speed) #include <stdio.h> main() { int i, sum = 0; for(i = 1; i <= 10; i++) { if(i % 4 ==0 || i % 8 == 0) sum += i; } printf("sum=%d \n", sum); return 0; } 결과값 : sum=12Process returned 0 (0x0) execution time : 0.032 s #include <stdio.h>main() { int i, sum = 0; for(i = 1; i <= 100; i++) { if(i % 4 ==0 || i % 8 == 0) sum += i; } printf("sum=%d \n", sum); return ..
고치는 방법 #include<stdio.h>#include<string.h>#define MAXLINE 1000int getline(char *line, int max);/*find:print lines that match pattern from 1st arg*/main(int argc, char *argv[]){ char line[MAXLINE]; long lineno = 0; int c, except = 0, number = 0, found = 0; while (--argc > 0 && (*++argv) [0] == '-') while (c = *++argc[0]) switch (c) { case 'x': except = 1; break; case 'n'..