본문 바로가기

분류 전체보기453

??오답 7강 문자열 문자열 갯수 세기 2020. 7. 22.
배열 array 총합 #include int main() { int arr[5]; int sum = 0; int i; for(i = 0; i < 5; i++) { scanf("%d ", &arr[i]); sum += arr[i]; } printf("%d", sum); return 0; } 2020. 7. 22.
자료형(type) 소수(double) 정수 int 문자 char 변수작성규칙 : 1. 알파벳이나 _로 시작 2. 숫자로 시작할 경우 앞에 _ 사용 : int _2pm; 2020. 7. 22.
컴파일 컴파일러 컴파일 : 프로그램(소스코드)을 기계어로 번역 컴파일러: 컴파일 해주는 프로그램 원시프로그램 or 소스코드 = 프로그래밍 언어로 작성한 프로그램 C코드도 소스코드 일종 컴파일과정 거쳐 생성한 기계어 코드 = 목적프로그램 2020. 7. 21.
값 입력받은 후 1부터 그 값까지 합 출력 int main() { int sum = 0; int i = 1; int j; scanf("%d", &j); while(i 2020. 7. 18.
구구단 for, while 둘 다 사용 #include int main() { int i = 1; int a; scanf("%d", &a); while(i < 10) { printf("%d X %d = %d\n", a, i, a * i); i++; } return 0; } int main() { int i; int a; scanf("%d", &a); for(i = 1; i < 10; i++) { printf("%d X %i = %d\n",a, i, a * i); } return 0; } 2020. 7. 18.
비트연산자 #include int main() { unsigned char input; // 0000 0011 unsigned char b = 6; // 0000 0110 scanf("%hhu", &input); unsigned char c = input & b; unsigned char d = input | b; unsigned char e = input ^ b; unsigned char f = ~ input; c = input & b; d = input | b; e = input ^ b; f = ~ input; printf("%d %d %d %d", c, d , e, f); return 0; } 2020. 7. 15.
Q.printf("나머지 : "); printf("a % b = %d", a % b);% 1개만 써도 결과가 나오는데 1개만 써도 되는건가요? 하경인(goorm)19. 07. 18. 오후 12:12 안녕하세요. 구름입니다. printf에서 %출력은 % 다음에 오는 문자에 따라 유형을 지정하여 값을 입력받는다는 것을 기억하실 겁니다. 예를 들어 printf("%d", 2); 라고 입력한 뒤 실행한다면 2가 출력되는 것처럼 말이죠. 그런데 이 %는 % 뒤에 받는 형식이 지정되지 않는 문자가 오면 % 뒤의 문자를 그대로 출력한다는 규칙을 갖고 있습니다. %d는 정수, %f는 실수를 받는 등 형식이 지정되어 있지만 %b는 아무 형식도 지정되어 있지 않기 때문에 printf("a % b"); 가 "a % b"로 정상 출력되는 것입니다. 만약 이 코드를 printf("a % d"); 로 변경한다면 "a % d"로 출력되는 것이 아니라 "a (쓰레기값)"으.. 2020. 7. 12.
#positional formationg, #named placeholder basic formatting: '{} {}'.format('one', 'two') 2020. 7. 12.
list끼리 + 는 되지만 - 는 안된다? / append , extend 차이 >>> a= [1,2,3] >>> a.append(4) >>> a [1, 2, 3, 4] >>> a.extend([5,6]) >>> a [1, 2, 3, 4, 5, 6] >>> a.remove() Traceback (most recent call last): File "", line 1, in a.remove() TypeError: remove() takes exactly one argument (0 given) >>> >>> a.remove(4) >>> a [1, 2, 3, 5, 6] >>> b =[7,8] >>> a + b [1, 2, 3, 5, 6, 7, 8] >>> a.insert(3,4) >>> a [1, 2, 3, 4, 5, 6] >>> a= a+ b >>> a [1, 2, 3, 4, 5, 6.. 2020. 6. 17.
"pithon" 을 "python"으로 바꾸기 >>> a = "pithon" >>> a[1] = y Traceback (most recent call last): File "", line 1, in a[1] = y NameError: name 'y' is not defined >>> a[1] = 'y' Traceback (most recent call last): File "", line 1, in a[1] = 'y' TypeError: 'str' object does not support item assignment >>> a[1] 'i' >>> a[:1] + "y" + a[2:] 'python' >>> 2020. 6. 16.
sequence of "non-decreasing" numbers def main(): print("Enter a sequence of non-decreasing numbers.") count = 0 last_num = float(input('Enter num: ')) cur_num = last_num while cur_num >= last_num: count += 1 #this line can go anywhere in body(while) last_num = cur_num cur_num = float(input('Enter num: ')) print("Thanks for playing") print("sequence length: " + str(count)) (Suggested 15 minutes) Write a program that asks the user to.. 2020. 6. 12.
print odd numbers (1 ~199) 3가지 방법 def main(): for i in range (100): print (i*2 +1) for i in range(200): if i % 2 == 1: print (i) v=1 while v 2020. 6. 12.