2021-01-07 TIL C 포인터, BOJ 1001(A-B)

esmin·2021년 1월 7일
0

C is the best

목록 보기
2/10

Visual Studio 소소한 단축키

Alt + Shift + . 같은변수 다중선택
shift + alt + keyboard Arrow 다중커서
F9 Break Point 지정


기초문법

데이터 형식.. 외우는게 힘드네

https://www.programiz.com/c-programming/c-data-types

문자열 출력

(출처: https://m.blog.naver.com/PostView.nhn?blogId=sharonichoya&logNo=220488567828&proxyReferer=https:%2F%2Fwww.google.com%2F)

문자열은 문자 char을 배열로 만들면 되는 것이다!

문자열 출력은 printf("%s", str);로 한다! "%s"가 사용되는 것이다!


기본적으로 쓰이는 헤더들

#include <math.h>: 기본적인 연산들 도와주는 헤더,

http://www.cplusplus.com/reference/cmath/ 에서 참고한 이미지
pow와 sqrt(square Root)만 있으면 된다.

포인터

& : 주소 주는애 (내꺼 가져가라)
'*' 주소 받는 애(주소 내놔라)


백준

C언어에 빠르게 익숙해지고자 기본 입출력 문제들을 후다닥 풀어보자.

BOJ 1001

/// <summary>
/// %d 글자는 아스키코드로 출력
/// %d 숫자는 숫자로 출력
/// %c 한글자 그대로 출력
/// %c
/// %d
/// %f
/// %s
/// 서식지정자에 따라서 출력결과가 변환된다. 
/// 포인터
/// 
/// </summary>
#define _CRT_SECURE_NO_WARNINGS // scanf 보안 경고로 인한 컴파일 에러 방지
#include <stdio.h>
int main() {
	int num1, num2;
	scanf("%d", &num1);
	scanf("%d", &num2);
	int num3 = num1 - num2;
	printf("%d \n", num3);
	return 0;
}

BOJ 10430

//#define _CRT_SECURE_NO_WARNINGS // scanf 보안 경고로 인한 컴파일 에러 방지
#include <stdio.h>
int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int one = (a + b) % c;
	int two = ((a % c) + (b % c)) % c;
	int thr = (a * b) % c;
	int four = ((a % c) * (b % c)) % c;
	printf("%d\n", one);
	printf("%d\n", two);
	printf("%d\n", thr);
	printf("%d\n", four);

}
a,b,c;
main(){
    scanf("%d %d %d",&a,&b,&c);
    printf("%d\n%d\n%d\n%d",(a+b)%c,((a%c)+(b%c))%c,(a*b)%c,((a%c)*(b%c))%c);
}

BOJ 11654

#define _CRT_SECURE_NO_WARNINGS // scanf 보안 경고로 인한 컴파일 에러 방지
#include <stdio.h>
int main() {
	char input;
	scanf("%c", &input);
	printf("%d", input);

}

1297 TV크기

#define _CRT_SECURE_NO_WARNINGS // scanf 보안 경고로 인한 컴파일 에러 방지
#include <stdio.h>
#include <math.h>
int main() {
	int diagonal; int w; int h;
	scanf("%d%d%d", &diagonal, &w, &h);
	double ww; double hh; double ratio;
	double diaratio = sqrt(pow(w, 2) + pow(h, 2));
	ratio = diagonal / diaratio;
	ww = w * ratio; hh = h * ratio;
	// TO Change double to int, Just use (int) infrontof Variable
	printf("%d %d", (int) ww, (int) hh);
}

2869 달팽이는 올라가고 싶다

0개의 댓글