MapleStory Finger Point Cute Line Smiley Blinking Hello Kitty Angel MapleStory Finger Point

πŸ’Ž C,C++,C#/C_code

Λšβ‚Šβœ©β€§β‚Š [C] μ½”λ“œ μ•Œκ³ λ¦¬μ¦˜ λͺ¨μŒ (20년도) Λšβ‚Šβœ©β€§β‚Š

HYEJU01 2023. 3. 27. 19:29

[C] λ©±μŠΉ κ΅¬ν•˜κΈ° (while λ¬Έ)

#include <stdio.h>

int main(void)
{

	int n;
	int x;
	int i = 1;

	printf("숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš” ");
	scanf_s("%d", &x);

	printf("====================\n");
	printf("n            n의제곱\n");
	printf("====================\n");

	n = 1;

	while (n <= x)
	{
		printf("%d             %d\n",n,n*n);

		n++;
	}

	return 0;

}

[C] 학점 κ΅¬ν•˜κΈ° + μŒμˆ˜λ‚˜μ˜¬λ•ŒκΉŒμ§€μž…λ ₯λ°›κΈ°

#include <stdio.h>
#include<limits.h>

int main()
{
	int jumsu = 0;
	float total, average;

	int i = 0;
	total = 0;

	printf("μ’…λ£Œν•˜λ €λ©΄ 음수λ₯Ό μž…λ ₯ν•˜μ‹œμ˜€ \n");

	//μ μˆ˜λ“€μ„ μŒμˆ˜κ°€ λ‚˜μ˜¬ λ•Œ κΉŒμ§€ λ°˜λ³΅ν•΄μ„œ μž…λ ₯λ°›μ•„μ„œ 총점을 κ΅¬ν•˜κ³ 
	//μž…λ ₯ν•œ 개수λ₯Ό μ„Όλ‹€

	while ( jumsu >= 0 )
	{
		printf("점수λ₯Ό μž…λ ₯ν•˜μ‹œμ˜€ \n");
		scanf_s("%d", &jumsu);

			total += jumsu;
			i++;
	}


	total = total - jumsu;
	i--;


	average = total / i;


	printf("총점 = %.2f\n", total);
	printf("평균 = %.2f\n", average);

	return 0;
}

[C] μ΅œλŒ€κ°’κ΅¬ν•˜κΈ° +EOF

#include <stdio.h>
#include<limits.h>

int main()
{
	int num;
	int min = INT_MAX;  //μΈνŠΈμ΅œλŒ“κ°’ 
	int max = INT_MIN;

	printf("νŠΉμ • μ •μˆ˜λ₯Ό μž…λ ₯ν•˜μ„Έμš”.\n μ’…λ£ŒλŠ” Ctrl+z \n");	
	while (scanf_s("%d", &num) != EOF) {  //-1
		if (num > max) 
			max = num;
	}
	printf("μ΅œλŒ€ = %d\n", max);

	return 0;
}


//eof  ctrl + z 3번 λˆŒλŸ¬μ•Ό μ’…λ£Œ 

[C] 학점 κ΅¬ν•˜κΈ° + μŒμˆ˜λ‚˜μ˜¬λ•ŒκΉŒμ§€μž…λ ₯λ°›κΈ°

#include <stdio.h>
#include<limits.h>

int main()
{
	int jumsu = 0;
	float total, average;

	int i = 0;
	total = 0;

	printf("μ’…λ£Œν•˜λ €λ©΄ 음수λ₯Ό μž…λ ₯ν•˜μ‹œμ˜€ \n");

	//μ μˆ˜λ“€μ„ μŒμˆ˜κ°€ λ‚˜μ˜¬ λ•Œ κΉŒμ§€ λ°˜λ³΅ν•΄μ„œ μž…λ ₯λ°›μ•„μ„œ 총점을 κ΅¬ν•˜κ³ 
	//μž…λ ₯ν•œ 개수λ₯Ό μ„Όλ‹€

	while ( jumsu >= 0 )
	{
		printf("점수λ₯Ό μž…λ ₯ν•˜μ‹œμ˜€ \n");
		scanf_s("%d", &jumsu);

			total += jumsu;
			i++;
	}


	total = total - jumsu;
	i--;


	average = total / i;


	printf("총점 = %.2f\n", total);
	printf("평균 = %.2f\n", average);

	return 0;
}

[C] 숫자 ν•© κ΅¬ν•˜κΈ° +EOF

#include <stdio.h>
#include<limits.h>

int main()
{

	int sum=0;
	int num;
	int i = 0;

	printf("숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”.");

	while (scanf_s("%d", &num) != EOF){
		sum += num;
	}

	printf("%d",sum);

	return 0;
}



[C] 멱승 κ΅¬ν•˜λŠ” ν•¨μˆ˜ λ§Œλ“€κΈ°

#include <stdio.h>

int square(int x);

int main()
{
	int n;
	printf("숫자 n을 μž…λ ₯ν•˜μ„Έμš”. ");
	scanf_s("%d", &n);

	printf("squareν•¨μˆ˜ κ²°κ³Ό = %d", square(n));

	return 0;
}

int square(int x) {
	
	return (x*x);
}

[C] 멱승 κ΅¬ν•˜λŠ” ν•¨μˆ˜ λ§Œλ“€κΈ° + 리턴값없이

void power(int x); //ν•¨μˆ˜ μ„ μ–Έ //ν˜•μ‹λ§€κ°œλ³€μˆ˜


int main() {

	power(3);

	return 0;
}

void power(int x) { //ν˜•μ‹λ§€κ°œλ³€μˆ˜
	printf("power ν•¨μˆ˜ 호좜 κ²°κ³Ό : %d",x*x);
}


[C] x의 y승 κ΅¬ν•˜λŠ” ν•¨μˆ˜ λ§Œλ“€κΈ°

#include <stdio.h>
#include <math.h>

int power(int x, int y); //ν•¨μˆ˜ μ„ μ–Έ //ν˜•μ‹λ§€κ°œλ³€μˆ˜

int main() {

	int x, y;


	printf("λ‘κ°œμ˜ μ •μˆ˜ μž…λ ₯\n");
	scanf_s("%d%d",&x,&y);

	int result = power(x,y);

	printf("%d의 %d승 = %d", x, y, result);
	
	return 0;
}

int power(int x, int y) { //ν˜•μ‹λ§€κ°œλ³€μˆ˜
	int result = 1;

	for (int i = 1; i <= y; i++) 
		result *= x;

	return result;
	
}

 


[C] 큰 수λ₯Ό κ΅¬ν•˜λŠ” ν•¨μˆ˜ λ§Œλ“€κΈ°

//ν•¨μˆ˜ -> λ°°μ—΄ 
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

//큰 수λ₯Ό κ΅¬ν•˜λŠ” ν•¨μˆ˜

int max(int x, int y);

int main() {

	int x, y;

	printf("λ‘κ°œμ˜ μ •μˆ˜ μž…λ ₯\n");

	scanf_s("%d%d",&x,&y);

	int result = max(x,y);

	printf("%d와 %d 쀑 큰수 = %d", x, y, result);
	
	return 0;
}

int max(int x, int y) {

	int result;

	if (x > y){
		result = x;
		}

	if (x < y) {
		result = y;
	}

	return result; 
}

[C] μ†Œμˆ˜ κ΅¬ν•˜λŠ” ν•¨μˆ˜ λ§Œλ“€κΈ°

//ν•¨μˆ˜ -> λ°°μ—΄ 
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

//μ†Œμˆ˜λ₯Ό κ΅¬ν•˜λŠ” ν•¨μˆ˜

int prime(int x);

int main() {

	int x;

	printf("μ •μˆ˜ x μž…λ ₯ \n");


	scanf_s("%d",&x);


	if (prime(x) == 1)
		printf("%dλŠ” μ†Œμˆ˜o.",x);
	else
		printf("%dλŠ” μ†Œμˆ˜x.",x);


	return 0;
}



int prime(int x) {

//μ•½μˆ˜ 2개만
	int count = 0;
	for (int i = 1; i <= x; i++) {

		if (x % i == 0) {
			count++;
		}
	}
	return (count == 2); // 0 1 λ°˜ν™˜ 0은 거짓
}


0 λ‚˜λˆ„λŠ” λ‚˜λ¨Έμ§€ 0


[C] 원 λ‘˜λ ˆ, 넓이 κ΅¬ν•˜κΈ°

------

//ν•¨μˆ˜ -> λ°°μ—΄ 
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define PI 3.14


//원 λ‘˜λ ˆ κ΅¬ν•˜λŠ” ν•¨μˆ˜

double circum(int x);


int main() {

	int x;

	printf("μ •μˆ˜ xλ₯Ό μž…λ ₯ \n");
	scanf_s("%d", &x);


	printf("μ›μ˜ λ‘˜λ ˆλŠ” %.2lf ", circum(x));


	return 0;
}


double circum(int x) {

	return (2 * PI * x);
}



[C/λ°°μ—΄] 학점 κ΅¬ν•˜κΈ°

//ν•¨μˆ˜ -> λ°°μ—΄ 
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define PI 3.14
int main() {

	int jumsu[3] = {0, };
	float total = 0, avg = 0;

	for (int i = 0; i < 3; i++)
	{
		scanf_s("%d",&jumsu[i]);
		total += jumsu[i];  
	}
	avg = (float) (total / 3);  //total이 μ‹€μˆ˜ν˜•μ΄λ‹ˆκΉŒ μžλ™ ν˜•λ³€ν™˜

	printf("κ΅­μ–΄ :%d\n", jumsu[0]);
	printf("μ˜μ–΄ : %d\n", jumsu[1]);
	printf("μˆ˜ν•™ : %d\n", jumsu[2]);

 	printf("총점 : %.2lf\n", total);
	printf("평균: %.2lf", avg);



	return 0;
}

[C/λ°°μ—΄] λ°°μ—΄ 좜λ ₯ν•˜κΈ°

//ν•¨μˆ˜ -> λ°°μ—΄ 
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define SIZE 5
int main() {

	int a[SIZE];

	for (int i = 0; i < SIZE; i++)
	{
		scanf_s("%d", &a[i]);
		printf("%d ", a[i]);
		
	}

	printf("\n");

	for (int i = SIZE-1 ; i >= 0; i--)
	{
		printf("%d ", a[i]);
	}

	return 0;
}



[C/λ°°μ—΄] 별 찍기

//ν•¨μˆ˜ -> λ°°μ—΄ 
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define SIZE 5


int main() {

	int a[SIZE] = { 10,20,30,40,50 };

	for (int i = 0; i < SIZE; i++)
	{
		printf("번호 %d ", a[i]);

		for (int s = 0; s < a[i]; s++) {
			printf("*");
		}

		printf("\n");
	}

	return 0;
}




[C/λ°°μ—΄] μ£Όμ‚¬μœ„

//μ£Όμ‚¬μœ„


//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define SIZE 6
#include <stdlib.h>

int main() {

	int freq[SIZE] = { 0 };

	for (int i = 0; i < 10000; i++)
	{
		++freq[rand() % 6];
	}
	printf("===================\n");
	printf("λ©΄             λΉˆλ„\n");
	printf("===================\n");

	for (int i = 0; i < SIZE; i++)

		printf("%3d             %3d\n", i, freq[i]);
	return 0;
}

 λΉˆλ„μˆ˜ κ³„μ‚°ν•˜λŠ” μ•Œκ³ λ¦¬μ¦˜
랜덀수λ₯Ό % 6으둜 λ‚˜λˆˆ λ‚˜λ¨Έμ§€λ“€μ„ 인덱슀둜 작고
0-5κΉŒμ§€ 인덱슀
λ‚˜λ¨Έμ§€ 값이 0-5μ‚¬μ΄μ˜ 값이 λ‚˜μ˜€λŠ”λ°
λ‚˜μ˜¬λ•Œλ§ˆλ‹€ 인덱슀 값을 ++1 ν•΄μ€€λ‹€
λΉˆλ„μˆ˜κ°€ μ¦κ°€ν•œλ‹€


[C] ν™˜μœ¨κ³„μ‚°

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h> 

int main() {
	
	int won = 0;
	int dol = 0;

	printf("원을 μž…λ ₯ν•˜μ„Έμš”");
	scanf("%d", &won);

	dol = won/1200;

	printf("원 %d \n λ‹¬λŸ¬ %d", won, dol);

	return 0;
}

[C/1ν•™κΈ°]

//if λ¬Έ

​

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int main(void) {

    //κ΅­μ–΄, μ˜μ–΄, μˆ˜ν•™ λ³€μˆ˜λ₯Ό μ„ μ–Έ

    int kor, eng, math;

    //총점, 평균을 μ„ μ–Έ

    int total, avg;

    //학점을 μ„ μ–Έ

    char grade;

 

    printf("κ΅­μ–΄, μ˜μ–΄, μˆ˜ν•™ 성적을 μž…λ ₯ν•˜μ„Έμš”.: ");

    scanf_s("?????????", &kor, ? ? ? ? , ? ? ? ? );

 

    //총점을 κ΅¬ν•œλ‹€.

    total = ? ? ? ? ? ? ;

    //평균을 κ΅¬ν•œλ‹€.

    avg = ? ? ? ? ;

 

    if (avg >= 90) {

        grade = 'A';

    }

    else if (avg ? ? ? ? ) //80이상이면 Bλ₯Ό μ£Όκ³ 

    else if (avg ? ? ? ? ) //70이상이면 Cλ₯Ό μ£Όκ³ 

    else if (avg ? ? ? ? ) //60이상이면 Dλ₯Ό μ£Όκ³ 

    else //60미만이면 Fλ₯Ό μ€€λ‹€.

 

    //κ΅­μ–΄, μ˜μ–΄, μˆ˜ν•™, 총점, 평균, 학점을 좜λ ₯ν•˜μ‹œμ˜€.

    printf(? ? ? ? ? ? );

    printf(? ? ? ? ? ? );

    printf(? ? ? ? ? ? );

    printf(? ? ? ? ? ? );

    printf(? ? ? ? ? ? );

    printf(? ? ? ? ? ? );

 

    return 0;

}

​

​

​

 #define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

​

//202003327 μž„ν˜œμ£Ό

​

int main(void) {

int kor, eng, math;

int total;

int avg;

char grade;

​

printf("κ΅­μ–΄, μ˜μ–΄, μˆ˜ν•™ 성적을 μž…λ ₯ν•˜μ„Έμš”. : ");

scanf_s("%d %d %d", &kor, &eng, &math);

​

total = kor + eng + math;

avg = total / 3;

​

if (avg >= 90)

{

grade = 'A';

}

else if (90 > avg && 80 <= avg) grade = 'B';

else if (80 > avg && 70 <= avg)grade = 'C';

else if (70 > avg && 60 <= avg) grade = 'D';

else grade = 'F';

​

​

printf("κ΅­μ–΄ 점수 : %d\n", kor);

printf("μ˜μ–΄ 점수 : %d\n", eng);

printf("μˆ˜ν•™ 점수 : %d\n", math);

printf("총점 : %d \n", total);

printf("평균 : %d \n", avg);

printf("학점 : %c \n", grade);

​

​

return 0;

}
//예제

4. 예제 2-6 μ—¬λŸ¬ 개의 μ„œμ‹ μ§€μ •μž μ‚¬μš©ν•˜κΈ°λ₯Ό μž‘μ„±ν•˜μ—¬ κ²°κ³Όλ₯Ό 좜λ ₯ν•˜μ‹œμ˜€.

​

#define _CRT_SECURE_NO_WARNINGS

 

#include <stdio.h>

 

int main()

{

    char name[20];

    int age;

    char gender;

 

    printf("이름, λ‚˜μ΄, 성별(M/F) 순으둜 μž…λ ₯ν•˜μ„Έμš” ^^*. \n");

    scanf("%s %d %c", name, &age, &gender);

 

    printf("이름 : %s\n", name);

    printf("이름 : %d\n", age);

    printf("이름 : %c\n", gender);

 

    return 0;

 


3. 예제 2-5 μž…λ ₯받은 10μ§„μˆ˜ μ •μˆ˜λ₯Ό 16μ§„μˆ˜λ‘œ λ³€ν™˜ν•΄μ„œ 좜λ ₯ν•˜μ‹œμ˜€.

​

​

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

 

int main()

 

{

    int num;

 

    printf("μ •μˆ˜? ");

    scanf("%d", &num);

 

    printf(" 10μ§„μˆ˜ %dλŠ” 16μ§„μˆ˜ %xμž…λ‹ˆλ‹€.\n", num, num);

 

    return 0;

}

2. 예제 2-4 정밀도 μ§€μ •ν•˜κΈ°λ₯Ό μž‘μ„±ν•˜μ—¬ κ²°κ³Όλ₯Ό 좜λ ₯ν•˜μ‹œμ˜€.

​

#include<stdio.h>  

 

int main()

{

    float x;

 

    x = 12.34567;

 

    printf("%f\n", x);

    printf("%.2f\n", x);

    printf("%8.2f\n", x);

 

 

    return 0;

 

}

1. 예제 2-3 문자 폭 μ§€μ •ν•˜κΈ°λ₯Ό μž‘μ„±ν•˜μ—¬ κ²°κ³Όλ₯Ό 좜λ ₯ν•˜μ‹œμ˜€.

​

#include<stdio.h>  

 

int main()

{

    int num = 12345;

 

    printf("%d\n", num);

    printf("%d\n", num * 10);

    printf("%d\n", num * 100);

    printf("%d\n", num * 1000);

 

 

    printf("%8d\n", num);

    printf("%8d\n", num * 10);

    printf("%8d\n", num * 100);

    printf("%8d\n", num * 1000);

    printf("%8d\n", num * 100000);

 

    printf("%08d\n", num);

 

    return 0;

 

}​
/λ³€μˆ˜

#define _CRT_SECURE_NO_WARNINGS

//#define PI 3.14

#include<stdio.h>

int main(void) {   

    int first;

    int second;

    ? ? ? ? ? ? ? ? ? ? ? ;//λ‘μˆ˜μ˜ 합을 μ €μž₯ν•˜λŠ” λ³€μˆ˜ μ„ μ–Έ

    ? ? ? ? ? ? ? ? ? ? ? ;//λ‘μˆ˜μ˜ μ°¨λ₯Ό μ €μž₯ν•˜λŠ” λ³€μˆ˜ μ„ μ–Έ

    ? ? ? ? ? ? ? ? ? ? ? ;//λ‘μˆ˜μ˜ 곱을 μ €μž₯ν•˜λŠ” λ³€μˆ˜ μ„ μ–Έ

    ? ? ? ? ? ? ? ? ? ? ? ;//λ‘μˆ˜μ˜ λͺ«μ„ μ €μž₯ν•˜λŠ” λ³€μˆ˜ μ„ μ–Έ

 

    printf("첫번째 μˆ˜λŠ” ?");

    scanf_s("???", &first);

 

    printf("λ‘λ²ˆμ§Έ μˆ˜λŠ” ?");

    scanf_s("???", ?????);

 

    ? ? ? = first + second;

    ? ? ? = first - second;

    ? ? ? = first * second;

    ? ? ? = first / second;

 

    printf("λ‘μˆ˜μ˜ ν•© = ???", hap);

    printf("λ‘μˆ˜μ˜ μ°¨ = ???", cha);

    printf("λ‘μˆ˜μ˜ κ³± = ???", gop);

    printf("λ‘μˆ˜μ˜ λͺ« = ???", mok);

    return 0;

}

//μ΅œλŒ€κ°’
#include<stdio.h>

//λ°°μ—΄ ν¬κΈ°λŠ” 맀크둜 μƒμˆ˜λ‘œ μ •μ˜

#define length 5

int main(void) {

    //num λ°°μ—΄ 생성, 초기치 값을 1,2,3,4,5둜 μ…‹νŒ…

    int num[length] = {3,4,7,8,14};

    int max=0;

    int i;

    //ν•΄λ‹Ή λ°°μ—΄μ˜ μˆ«μžλ“€μ„ λΉ„κ΅ν•΄μ„œ μ΅œλŒ€κ°’μ„ κ³ λ₯Έλ‹€.

    for (i =0; i < length; i++) {

        if (max < num[i])

            max = num[i];

    }      

    //λ°°μ—΄ μ›μ†Œλ“€μ„ 좜λ ₯ν•œλ‹€.

    for (i = 0; i < length; i++)

        printf("num[%d] = %d\n", i, num[i]);

    printf("μ΅œλŒ€κ°’ = %d", max);

 

 

    return 0;

}

β˜…Cν”„λ‘œκ·Έλž¨ 개발 κ³Όμ •

1. μ†ŒμŠ€νŒŒμΌ μž‘μ„±

2. μ „μ²˜λ¦¬κΈ°

3. 컴파일(ꡬ문뢄석, μ½”λ“œμƒμ„±, 링크) - μ»΄νŒŒμΌμ—λŸ¬

4. 링크 (링컀) - λ§ν¬μ—λŸ¬

5. μ‹€ν–‰ - μ‹€ν–‰μ—λŸ¬

​

β˜…λ‹¨μΆ•ν‚€

μƒˆν”„λ‘œμ νŠΈ Ctrl + Shift + N

μ‹€ν–‰ Ctrl + F5

​

λ¬Έμžμ •μˆ˜

#include <stdio.h>

void Pr_ch(void);

 

int main(void) {

    char input;

    int n = 0;

 

    printf("λ¬Έ> λ¬Έμžμ™€ 횟수(μ •μˆ˜) μž…λ ₯: ");

    scanf_s("%c %d", &input, sizeof(input), &n);

    Pr_ch(input, n);

 

    return 0;

}

 

void Pr_ch(char ch, char num) {

 

    int i;

 

    printf("λ‹΅>");

    for(i = 1; i <= num; i++)

        printf(" %c", ch);

    printf(" : %d회 좜λ ₯ μ™„λ£Œ\n", i - 1);

}
//λ‚œμˆ˜
#include <stdio.h>

#include <stdlib.h>

 

int main(void) {

    printf("1~45 μ€‘μ—μ„œ 숫자 6개 좜λ ₯ \n");

    printf("rand() : ");

    for (int i = 1; i <= 6; i++)

        printf(" %d ", rand()); //μž„μ˜ λ‚œμˆ˜ 6κ°œκ°€ 좜λ ₯

 

        printf("\n");

        printf("rand() %% 45: ");

 

    for (int i = 1; i <= 6; i++)

        printf(" %d ", (rand() % 45)); //μž„μ˜μ˜ λ‚œμˆ˜ 5개 45둜 λ‚˜λˆˆ 숫자 6개λ₯Ό 좜λ ₯ (0~44μ‚¬μ΄μ˜ κ°’ 좜λ ₯)

 

    printf("\n");

    printf("1 + rand() %% 45) :  ");

 

    for (int i = 1; i <= 6; i++)

        printf(" %d ", 1 + (rand() % 45)); //1μ—μ„œ 45μ‚¬μ΄μ˜ κ°’ 좜λ ₯

    printf("\n");

 

    return 0;

}
//λ‚˜μ΄κ³„μ‚°

#include <stdio.h>

#include <math.h>

 

int main(void) {

    double result, age1, age2;

    printf("λ‚΄ λ‚˜μ΄ μž…λ ₯: ");

    scanf_s("%lf", &age1);

    printf("μ„ μƒλ‹˜ λ‚˜μ΄ μž…λ ₯ : ");

    scanf_s("%lf", &age2);

 

    result = age1 - age2;

    printf("\n %.01fμ„Έ - %.01fμ„Έ =  %3.01fμ„Έ\n", age1, age2, result);

 

    result = fabs(age1 - age2); //μ ˆλŒ€μΉ˜ κ΅¬ν•˜λŠ” 라이브러리 ν•¨μˆ˜ ν˜ΈμΆœν•œκ±°μž„

 

    printf("μ ˆλŒ€κ°’ %0.1fμ„Έ - %.01fμ„Έ = %3.01fμ„Έ", age1, age2, result);

 

    return 0;

}
//μ΅œμ†Œκ°’
#include<stdio.h>

//λ°°μ—΄ ν¬κΈ°λŠ” 맀크둜 μƒμˆ˜λ‘œ μ •μ˜

#define length 5

int main(void) {

    //num λ°°μ—΄ 생성, 초기치 값을 1,2,3,4,5둜 μ…‹νŒ…

    int num[length] = { 3,4,7,8,14 };

    int min = num[0];

    int i;

    //ν•΄λ‹Ή λ°°μ—΄μ˜ μˆ«μžλ“€μ„ λΉ„κ΅ν•΄μ„œ μ΅œλŒ€κ°’μ„ κ³ λ₯Έλ‹€.

    for (i = 0; i < length; i++) {

        if (min > num[i])

            min = num[i];

    }

    //λ°°μ—΄ μ›μ†Œλ“€μ„ 좜λ ₯ν•œλ‹€.

    for (i = 0; i < length; i++)

        printf("num[%d] = %d\n", i, num[i]);

    printf("μ΅œμ†Œκ°’ = %d", min);

 

 

    return 0;

}

#include <stdio.h>

​

int main() {

​

​

char a[100];

char b[100];

char c[100];

char d_str[100];

char e[100];

​

int n = 0;

int x = 0;

​

scanf_s("%s",e); //scanf :: ν˜•μ‹μ— 맞게 μž…λ ₯λ°›μŒ (μž…λ ₯) **λ¬Έμž₯을 λ‹€ λͺ»μ½μŒ

​

fgets(a, sizeof(a), stdin); // fgets ::ν•œμ€„μ˜λ¬Έμžμ—΄λ°›μ•„μ˜€κ³ +μ€„λ°”κΏˆλ¬Έμžμ €μž₯ (μž…λ ₯)​

printf(a);  (좜λ ₯)



gets_s(b, sizeof(b)); //gets_s  :: ν•œμ€„μ˜λ¬Έμžμ—΄λ°›μ•„μ˜€κ³ +μ€„λ°”κΏˆXXX (μž…λ ₯)​

printf(b); //pirntf :: μ€„λ°”κΏˆλ¬Έμž μˆ˜λ™μž…λ ₯ ν›„ 좜λ ₯ (좜λ ₯)​



puts("hello"); // puts :: μ€„λ°”κΏˆλ¬Έμž μžλ™μΆœλ ₯ (좜λ ₯)​

​

sscanf(c, "%d", &n);// c에 μ •μˆ˜%d λ₯Ό μ½μ–΄μ„œ %x에 μ €μž₯  (μž…λ ₯)​​



int h=0, m=0, s=0;

​

sprintf(d_str, "%02d:%02d:%02d", h, m, s); // sprintf :: ν˜•μ‹λ¬Έμžμ—΄μ— 따라 λ¬Έμžμ—΄ 생성 ν›„ 버퍼에 μ €μž₯  (μž…λ ₯)​​

puts(d_str); (좜λ ₯)​​

​

}​

​

=====================

​

#define CRT_SECURE_NO_WARINGS

#include <stdio.h>

​

int main() {

​

char s1[100] = "hello";

char s2[100] = "test";

​

printf("λ¬Έμžμ—΄ s1을 μž…λ ₯ν•˜μ„Έμš”");

scanf("%s",s1);

gets(s1);

​

printf("λ¬Έμžμ—΄ s2을 μž…λ ₯ν•˜μ„Έμš”");

scanf("%s",s2);

gets(s2);

​

printf("볡사전 s1 = %s\n", s1);

printf("볡사전 s2 = %s\n", s2);

puts(s1);

puts(s2);

​

strcpy(s2, s1); // s1을 s2둜 λ³΅μ‚¬ν•œλ‹€.

​

printf("s1의 κΈΈμ΄λŠ” %d\n", strlen(s1));

printf("s2의 κΈΈμ΄λŠ” %d\n", strlen(s2));

​

printf("볡사후 s1 = %s\n", s1);

printf("볡사후 s2 = %s\n", s2);

​

strcat(s2, s1); //s2에 s1을 뢙인닀.

​

printf("μ—°κ²°ν›„ s1 = %s\n", s1);

printf("μ—°κ²°ν›„ s2 = %s\n", s2);

​



if (strcmp(s1, s2) == 0)  //λ¬Έμžμ—΄λΉ„κ΅ κ°™μœΌλ©΄ 0, μ™Όμͺ½μ΄ν¬λ©΄ μ–‘μˆ˜

printf("s1와 s2의 λ¬Έμžμ—΄ 값이 κ°™λ‹€\n");

else

printf("s1와 s2의 λ¬Έμžμ—΄ 값이 λ‹€λ₯΄λ‹€\n");

​

​

​

return 0;

}​

​

​

​

=============

​

#define CRT_SECURE_NO_WARINGS

#include <stdio.h>

​

int main() {

​

char s1[100] = "";

char s2[100] = "";

​

char *p = NULL;

​

printf("λ¬Έμžμ—΄ s1을 μž…λ ₯ν•˜μ„Έμš”");

gets(s1);

​

printf("λ¬Έμžμ—΄ s2을 μž…λ ₯ν•˜μ„Έμš”");

gets(s2);

​

puts(s1);

puts(s2);

​

p = strchr(s1, '.'); //νŠΉμ •μœ„μΉ˜ 리턴

​

​

printf("pκ°€ κ°€λ¦¬ν‚€λŠ” κ³³ = %s", p);// μ°Ύμ€μœ„μΉ˜μ£Όμ†Œ λ¦¬ν„΄ν•˜κ³  κ·Έ μ΄ν›„κ°’μΆœλ ₯ν•˜λ―€λ‘œ

​

​

​

​

return 0;

}​

​

==========

​

char s1[100] = "test.txt";

char s2[100] = "010-1234-5678";

​

char *p = NULL;

​

​

p = strchr(s1, '.'); //νŠΉμ •μœ„μΉ˜ 리턴

​

p = strtok(s1, '.');

​

p = strtok(s2, "-");

printf("ꡭ번: %s\n", p);

p = strtok(NULL, "-");

printf("μ•žμžλ¦¬: %s\n",p);

p = strtok(NULL, "-");

printf("λ’·μžλ¦¬: %s\n", p);

printf("pκ°€ κ°€λ¦¬ν‚€λŠ” κ³³ = %s", p);// μ°Ύμ€μœ„μΉ˜μ£Όμ†Œ λ¦¬ν„΄ν•˜κ³  κ·Έ μ΄ν›„κ°’μΆœλ ₯ν•˜λ―€λ‘œ

​==============

​

#define CRT_SECURE_NO_WARINGS

#include <stdio.h>

​

int main() {

​

char s1[100] = "test.txt";

char s2[100] = "HELLO";

​

​

for (int i = 0; i < strlen(s1); i++) {

s1[i] = toupper(s1[i]);

}

printf("μ†Œλ¬Έμžμ—μ„œ λŒ€λ¬Έμžλ‘œ s1 = %s\n", s1);

​

for (int i = 0; i < strlen(s2); i++) {

s2[i]=tolower(s2[i]);

}

printf("μ†Œλ¬Έμžμ—μ„œ λŒ€λ¬Έμžλ‘œ s2 = %s\n", s2);

​

​

return 0;

}​

​

​

===============

​

#define CRT_SECURE_NO_WARINGS

#include <stdio.h>

#include <string.h>

int count_space(const char *s);

​

int main() {

char str[64] = "this program\ttests const pointer to string\n"; // \tνƒ­ν‚€, \n문자 곡백

puts(str);

printf("곡백문자의 개수 :  %d\n", count_space(str));

​

return 0;

}

​

int count_space(const char* s) {

int count = 0;

while (s[0] != '\0') {

if (isspace(s[0]))

count++;

s++;

}

return count;

}​

===============​

​

#define CRT_SECURE_NO_WARINGS

#include <stdio.h>

#include <string.h>

​

#define SIZE 128

​

int swap_string(char*lhs, char* rhs, int size);

​

int main() {

char str1[SIZE] = "";

​

char str2[SIZE] = "";



printf("λ¬Έμžμ—΄ 2개? ");

scanf("%s %s", str1, str2);

​

printf("<<κ΅ν™˜μ „>> str1=%s, str2=%s \n", str1, str2);

​

​

swap_string(str1, str2, SIZE);

printf("<<κ΅ν™˜ν›„>> str1=%s, str2=%s \n", str1, str2);

​

​

return 0;

}

​

int swap_string(char*lhs, char* rhs, int size)

{

int lhs_len = strlen(lhs);

​

int rhs_len = strlen(rhs);

​

char temp[SIZE] = "";

​

if (lhs_len + 1 > size || rhs_len + 1 > size)

return 0;

​

strcpy(temp, lhs);

strcpy(lhs, rhs);

strcpy(rhs, temp);

​

return 1;

​

​

}​

==============

​

#define CRT_SECURE_NO_WARINGS

#include <stdio.h>

#include <string.h>

​

#define SIZE 128

​

int main() {

​

​

char books[5][30] = { "wonder",

"me before you",

"the honger game",

"twilight",

"harry potter",

};

​

int i = 0;

​

puts("<<λ³€κ²½μ „>>");

for (i = 0; i < 5; i++) {

printf("μ±… 제λͺ© : %s\n", books[i]);

}

​

for (i = 0; i < 5; i++) {

if (islower(books[i][0])) {

books[i][0] = toupper(books[i][0]);

}

}

​

puts("<<λ³€κ²½ν›„>>");

for (i = 0; i < 5; i++)

printf("μ±… 제λͺ© : %s\n", books[i]);

​

return 0;

}​

====

​

#define CRT_SECURE_NO_WARINGS

#include <stdio.h>

#include <string.h>

​

#define SIZE 128

​

int main() {

​

​

char books[5][30] = { "wonder",

"me before you",

"the honger game",

"twilight",

"harry potter",

};

​

int i = 0;

​

puts("<<λ³€κ²½μ „>>");

for (i = 0; i < 5; i++) {

printf("μ±… 제λͺ© : %s\n", books[i]);

}

​

for (i = 0; i < 5; i++) {

if (islower(books[i][0])) {

books[i][0] = toupper(books[i][0]);

}

}

​

puts("<<λ³€κ²½ν›„>>");

for (i = 0; i < 5; i++)

printf("μ±… 제λͺ© : %s\n", books[i]);

​

​

printf("books 의 길이 :: %d", strlen(books[1]));



for (i = 0; i <= 12; i++) {

books[4][i] = toupper(books[4][i]);

}

printf("λ§ˆμ§€λ§‰ μ±… : %s \n",books[4]);





​

​

return 0;

}​

======

​

#define CRT_SECURE_NO_WARINGS

#include <stdio.h>

#include <string.h>

#include <ctype.h>

​

#define MAX 6

#define BUF_SZ 30

​

int swap_string(char* lhs, char*rhs, int size);

​

int main() {

​

​

char books[5][30] = { "wonder",

"me before you",

"the honger game",

"twilight",

"harry potter",

};

​

//int i = 0;

​

//puts("<<λ³€κ²½μ „>>");

//for (i = 0; i < 5; i++) {

// printf("μ±… 제λͺ© : %s\n", books[i]);

//}

​

//for (i = 0; i < 5; i++) {

// if (islower(books[i][0])) {

// books[i][0] = toupper(books[i][0]);

// }

//}

​

//puts("<<λ³€κ²½ν›„>>");

//for (i = 0; i < 5; i++)

// printf("μ±… 제λͺ© : %s\n", books[i]);

​

​

// printf("books 의 길이 :: %d", strlen(books[1]));

//

// for (i = 0; i <= 12; i++) {

// books[4][i] = toupper(books[4][i]);

// }

// printf("λ§ˆμ§€λ§‰ μ±… : %s \n",books[4]);



int i, j;

int index;

​

puts("<<μ •λ ¬ μ „>>");

for (i = 0; i < MAX; i++) {

index = i;

​

for (j = i + 1; j < MAX; j++) {

if (strcmp(books[index], books[j]) > 0)

index = j;

​

}

if (i != index) {

swap_string(books[index], books[i], BUF_SZ);

}

}

​

puts("<<μ •λ ¬ ν›„>>");

for (i = 0; i < MAX; i++) {

puts(books[i]);

​

}

​

return 0;

}

​

int swap_string(char* lhs, char*rhs, int size) {

​

​

int lhs_len = strlen(lhs);

int rhs_len = strlen(rhs);

char temp[BUF_SZ] = "";

​

if (lhs_len + 1 > size || rhs_len + 1 > size)

return 0;

​

strcpy(temp, lhs);

strcpy(lhs, rhs);

strcpy(rhs, temp);

​

return 1;

}​

 

 


​

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

​

int main() {

   const char* str_menu[] = {

       "끝내기", "μƒˆ ν”„λ‘œμ νŠΈ", "ν”„λ‘œμ νŠΈ μ—΄κΈ°", "μ†”λ£¨μ…˜ λΉŒλ“œ", "디버깅 μ‹œμž‘"

   };

   int sz_menu = sizeof(str_menu) / sizeof(str_menu[0]);

   int menu;

   while (1) {

       int i;

       for (i = 0; i < sz_menu; i++)

           printf("%d.%s\n", i, str_menu[i]);

       printf("메뉴 선택? ");

       scanf("%d", &menu);

       if (menu == 0)

           break;

       else if (menu > 0 && menu < sz_menu)

           printf("%s 메뉴λ₯Ό μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.\n\n", str_menu[menu]);

       else

           printf("잘λͺ» μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.\n\n");

   }

   return 0;

}​

​

--

#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> 
int main() { 
char str_menu[5][20];
int sz_menu = sizeof(str_menu) / sizeof(str_menu[0]);
int menu; int i;
for (i = 0; i < 5; i++) { 
printf("메뉴λͺ…을 μž…λ ₯ν•˜μ‹œμ˜€");
scanf("%s", str_menu[i]); 
} 
while (1) {
    int i; 
    for (i = 0; i < sz_menu; i++) 
    printf("%d.%s\n", i, str_menu[i]);
    printf("메뉴 선택? ");
    scanf("%d", &menu);
    if (menu == 0) 
    	break;
    else if (menu > 0 && menu < sz_menu)
      	printf("%s 메뉴λ₯Ό μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.\n\n", str_menu[menu]);
    else 
    	printf("잘λͺ» μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.\n\n"); 
} 
return 0; 
}​

​

---

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

​

int main() {

   const char* str_menu[5][20];

   int sz_menu = sizeof(str_menu) / sizeof(str_menu[0]);

   int menu = 0;

​

   //메뉴λͺ…을 ν‚€λ³΄λ“œλ‘œ μž…λ ₯λ°›κΈ°

   //λ¬Έμžμ—΄λ°°μ—΄μ— μ €μž₯

​

​

   printf("메뉴 이름 μ μ–΄μ£Όμ„Έμš”");

   for (int i =0; i< sz_menu; i++)

       scanf("%s", str_menu[sz_menu]);

​

   while (1) {

       int i;

​

       printf("메뉴 선택? ");

       scanf("%d", &menu);

​

       if (menu == 0)

           break;

​

       else if (menu > 0 && menu < sz_menu)

           printf("%s μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.\n\n", str_menu[menu]);

​

       else

           printf("잘λͺ» μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.\n\n");

   }

   return 0;

}​

------------

​

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

#include<stdlib.h>

​

int main() {

 

   char s1[] = "100";

   char s2[] = "12.93";

   char buffer[100];

​

​

   int i;

   double d;

   double result;

​

   //λ¬Έμžμ—΄ s1은 μ •μˆ˜λ‘œ λ³€ν™˜ν•œλ‹€.

​

   i = atof(s1); // λ¬Έμžμ—΄ > μ •μˆ˜λ‘œ λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜

   d = atof(s2);

​

   result = i + d;

​

   sprintf(buffer, "%f", result);

   printf("μ—°μ‚°κ²°κ³ΌλŠ” %s μž…λ‹ˆλ‹€. \n", buffer);

​

   return 0;

}​

​

----------------

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

#include<stdlib.h>

#include <ctype.h>

#define SIZE 100

​

int main() {

 

​

   char str[SIZE];

   int count = 0;

​

   scanf("%s", str);

​

   for (int i = 0; i < SIZE; i++) {

     // ispunct()

       if (str[i]=='.')

           count++;

   }

​

   printf("κ΅¬λ‘μ μ˜ κ°œμˆ˜λŠ” %d 개 μž…λ‹ˆλ‹€.", count);

​

​

   return 0;

}​

---------------------------

​

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

#include<stdlib.h>

#include <ctype.h>

#define SIZE 100

​

int count_period(const char* s);

​

int main() {

 

​

   char str[SIZE];

   int count = 0;

   printf("λ¬Έμžμ—΄μ„ μž…λ ₯λ°›λŠ”λ‹€.");

   scanf("%s", str);

   printf("%s\n", str);

​

​

   //for (int i = 0; i < SIZE; i++) {

   //  // ispunct()

   //    if (str[i]=='.')

   //        count++;

   //}

​

   printf("κ΅¬λ‘μ μ˜ κ°œμˆ˜λŠ” %d 개 μž…λ‹ˆλ‹€.", count_period(str));

​

   return 0;

}

​

   int count_period(const char* s) {

       int count = 0;

       while (s[0] != '\0') {

           if (ispunct(s[0]))

               count++;

           s++;

       }

​

       return count;

   }

​

​-------------------------

​

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

#include<stdlib.h>

#include <ctype.h>

#define SIZE 100

​

int count_period(const char* s);

​

int main() {

 

​

   char str[SIZE];

   int count = 0;

   printf("λ¬Έμžμ—΄μ„ μž…λ ₯λ°›λŠ”λ‹€.");

/*   scanf("%s", str);*/

   gets(str);

   printf("%s\n", str);

​

​

   //for (int i = 0; i < SIZE; i++) {

   //  // ispunct()

   //    if (str[i]=='.')

   //        count++;

   //}

​

   printf("κ΅¬λ‘μ μ˜ κ°œμˆ˜λŠ” %d 개 μž…λ‹ˆλ‹€.", count_period(str));

​

   return 0;

}

​

   int count_period(const char* s) {

       int count = 0;

       while (s[0] !='\0') {

           if (ispunct(s[0]))

               count++;

           s++;

       }

​

       return count;

   }

--------------------------------------

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

#include<stdlib.h>

#include <ctype.h>

#define SIZE 100

​

int main() {



   char str[SIZE];

   int count = 0;

   printf("λ¬Έμžμ—΄μ„ μž…λ ₯λ°›λŠ”λ‹€.");

   gets(str);

   printf("%s\n", str);

​

​

for (int i = 0; i < strlen(str); i++) {

if (ispunct(str[i]))

       count++;

}

​

   printf("κ΅¬λ‘μ μ˜ κ°œμˆ˜λŠ” %d 개 μž…λ‹ˆλ‹€.", count);

​

   return 0;

}

​

------------------------------------------

​

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

#include<stdlib.h>

#include <ctype.h>

#define SIZE 100

​

​

struct  contact

{

   char name[20];

   char phone[20];

   int ringtone;

};

int main() {

​

   printf("%d", sizeof(struct contact));

​

   return 0;

}

​​

-------------------------------

 

#include<Stdio.h>
struct contact
{
    char name[20];
    char phone[20];
    int ringtone;
};
int main(void) {
    struct contact ct = { "김석진","0110101003",0 };
    struct contact ct1 = { 0 }, ct2 = { 0 };

    ct.ringtone = 1;
    strcpy(ct.phone,"010123415");
    printf("이름: %s\n", ct.name);
    printf("μ „ν™”λ²ˆν˜Έ: %s\n", ct.phone);
    printf("λ²¨μ†Œλ¦¬: %d\n", ct.ringtone);

    return 0;
}​
​
​

​

-------

​

#include<Stdio.h>

struct contact

{

   char name[20];

   char phone[20];

   int ringtone;

};

int main(void) {

   struct contact ct = { "김석진","0110101003",0 };

   struct contact ct1 = { 0 }, ct2 = { 0 };

​

   ct.ringtone = 1;

   strcpy(ct.phone, "010123415");

   printf("이름: %s\n", ct.name);

   printf("μ „ν™”λ²ˆν˜Έ: %s\n", ct.phone);

   printf("λ²¨μ†Œλ¦¬: %d\n", ct.ringtone);

​

   strcpy(ct1.name, "μž„ν˜œμ£Ό");

   strcpy(ct1.phone, "01054625192");

   ct1.ringtone = 324;

   printf("이름: %s\n", ct1.name);

   printf("μ „ν™”λ²ˆν˜Έ: %s\n", ct1.phone);

   printf("λ²¨μ†Œλ¦¬: %d\n", ct1.ringtone);

​

   return 0;

}​

​

--------------

#define _CRT_SECURE_NO_WARNINGS

#include<Stdio.h>

struct contact

{

   char name[20];

   char phone[20];

   int ringtone;

};

int main(void) {

   struct contact ct = { "김석진","0110101003",0 };

   struct contact ct1 = { 0 }, ct2 = { 0 };

​

   ct.ringtone = 1;

   strcpy(ct.phone, "010123415");

   printf("이름: %s\n", ct.name);

   printf("μ „ν™”λ²ˆν˜Έ: %s\n", ct.phone);

   printf("λ²¨μ†Œλ¦¬: %d\n", ct.ringtone);

​

   strcpy(ct1.name, "μž„ν˜œμ£Ό");

   strcpy(ct1.phone, "01054625192");

   ct1.ringtone = 324;

   printf("이름: %s\n", ct1.name);

   printf("μ „ν™”λ²ˆν˜Έ: %s\n", ct1.phone);

   printf("λ²¨μ†Œλ¦¬: %d\n", ct1.ringtone);

​

   printf("이름:\n");

   scanf("%s", ct2.name);

   printf("μ „ν™”λ²ˆν˜Έ:\n");

   scanf("%s", ct2.phone);

   printf("λ²¨μ†Œλ¦¬:\n");

   scanf("%d", &ct2.ringtone);

​

   printf("이름: %s\n", ct2.name);

   printf("μ „ν™”λ²ˆν˜Έ: %s\n", ct2.phone);

   printf("λ²¨μ†Œλ¦¬: %d\n", ct2.ringtone);

​

​

​

   return 0;

}​

--------------​

​

#define _CRT_SECURE_NO_WARNINGS

#include<Stdio.h>

struct student

{

   char name[20];

   char phone[20];

   int age;

   char addr[50];

​

};

int main(void) {

   struct student s1, s2, s3;

​

​

   strcpy(s1.name, "μž„ν˜œμ£Ό");

   strcpy(s1.phone, "01054625192");

   s1.age = 20;

   strcpy(s1.addr, "μ„œμšΈμ‹œ μ€‘λž‘κ΅¬ λ©΄λͺ©λ™");

​

   printf("이름: %s\n", s1.name);

   printf("μ „ν™”λ²ˆν˜Έ: %s\n", s1.phone);

   printf("λ‚˜μ΄: %d\n", s1.age);

   printf("μ£Όμ†Œ: %s\n", s1.addr);

​

​

​

   return 0;

}​

-------------------------

​

​

#define _CRT_SECURE_NO_WARNINGS

#include<Stdio.h>

#include<stdint.h>

​

struct sungjuk

{

   int kor;

   int eng;

   int math;

   double total;

   double avg;

​

};

int main(void) {

   struct sungjuk s1 = { 0 };

​

     printf("κ΅­μ–΄:\n");

     scanf("%d", &s1.kor);

​

     printf("μˆ˜ν•™:\n");

     scanf("%d", &s1.math);

​

       printf("μ˜μ–΄:\n");

       scanf("%d", &s1.eng);

​

       s1.total = s1.kor + s1.math + s1.eng;

       s1.avg = s1.total / 3;

​

   printf("κ΅­μ–΄: %d\n", s1.kor);

   printf("μˆ˜ν•™: %d\n", s1.math);

   printf("μ˜μ–΄: %d\n", s1.eng);

   printf("총점: %f\n", s1.total);

   printf("평균: %f\n", s1.avg);

​

​

​

   return 0;

}​

------------------------

#define _CRT_SECURE_NO_WARNINGS

#include<Stdio.h>

#include<stdint.h>

​

struct sungjuk

{

   int kor;

   int eng;

   int math;

   double total;

   double avg;

   char grade;

​

};

int main(void) {

   struct sungjuk s1 = { 0 };

​

     printf("κ΅­μ–΄:\n");

     scanf("%d", &s1.kor);

​

     printf("μˆ˜ν•™:\n");

     scanf("%d", &s1.math);

​

       printf("μ˜μ–΄:\n");

       scanf("%d", &s1.eng);

​

       s1.total = s1.kor + s1.math + s1.eng;

       s1.avg = (double) s1.total / 3;

​

       if (s1.avg >= 90 && s1.avg <= 100)

           s1.grade = 'A';

       else if (s1.avg>=80 && s1.avg<=89)

           s1.grade = 'B';

       else if (s1.avg >= 70 && s1.avg <= 70)

           s1.grade = 'C';

       else if (s1.avg >= 60 && s1.avg <= 69)

           s1.grade = 'D';

       else

           s1.grade = 'F';

​

​

​

   printf("κ΅­μ–΄: %d\n", s1.kor);

   printf("μˆ˜ν•™: %d\n", s1.math);

   printf("μ˜μ–΄: %d\n", s1.eng);

   printf("총점: %f\n", s1.total);

   printf("평균: %f\n", s1.avg);

   printf("학점: %c\n", s1.grade);

​

​

   return 0;

}​

​

 

 

 


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

​

struct Student

{

   char name[20];

   char phone[20];

   int age;

   char addr[150];

};

​

int main() {

   struct Student s;

   /*strcpy(s.name, "μ˜€μ„Έμš±");

   strcpy(s.phone, "010-8725-0916");

   s.age = 20;

   strcpy(s.addr, "μ„œμšΈμ‹œ μ†‘νŒŒκ΅¬ 방이동");*/

   printf("이름은?");

   gets(s.name);

   printf("μ „ν™”λ²ˆν˜ΈλŠ”?");

   gets(s.phone);

   printf("μ£Όμ†ŒλŠ”?");

   gets(s.addr);

   printf("λ‚˜ 이?");

   scanf("%d", &s.age);

​

​

   printf("이 름: %s\n", s.name);

   printf("μ „ν™”λ²ˆν˜Έ: %s\n", s.phone);

   printf("λ‚˜μ΄: %d\n", s.age);

   printf("μ£Όμ†Œ: %s\n", s.addr);

   return 0;

}​

--------------------------------------

​

struct Circle

{

   double x;

   double y;

   double radius;

};

​

int main() {

   struct Circle c;

   c.x = 5;

   c.y = 4;

   c.radius = 10;

​

   printf("μ›μ˜ xμ’Œν‘œ: %1.f\n", c.x);

   printf("μ›μ˜ yμ’Œν‘œ: %1.f\n", c.y);

   printf("μ›μ˜ λ°˜μ§€λ¦„: %1.f\n", c.radius);

​

   return 0;

}​

​

--------------------------------------

​​

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

​

struct Circle

{

   int x;

   int y;

   double radius;

};

​

int main() {

   struct Circle c;

   c.x = 5;

   c.y = 4;

   c.radius = 10;

​

   struct Circle c1;

   printf("x\n");

   scanf("%d",&c1.x);

   printf("y\n");

   scanf("%d",&c1.y);

   printf("λ°˜μ§€λ¦„\n");

   scanf("%lf", &c1.radius);

​

   printf("μ›μ˜ xμ’Œν‘œ: %d\n", c.x);

   printf("μ›μ˜ yμ’Œν‘œ: %d\n", c.y);

   printf("μ›μ˜ λ°˜μ§€λ¦„: %1.f\n", c.radius);

   printf("μ›μ˜ xμ’Œν‘œ: %d\n", c1.x);

   printf("μ›μ˜ yμ’Œν‘œ: %d\n", c1.y);

   printf("μ›μ˜ λ°˜μ§€λ¦„: %1.f\n", c1.radius);

   return 0;

}​

--------------------------------------​

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

​

struct Circle

{

   int x;

   int y;

   int radius;

   double circum; //λ‘˜λ ˆ

   double area; //면적

};

​

int main() {

   struct Circle c;

   c.x = 5;

   c.y = 4;

   c.radius = 10;

   c.circum = 2*3.14*c.radius;

   c.area = 3.14*c.radius*c.radius;

​

   struct Circle c1;

   printf("x\n");

   scanf("%d",&c1.x);

   printf("y\n");

   scanf("%d",&c1.y);

   printf("λ°˜μ§€λ¦„\n");

   scanf("%d", &c1.radius);

   c1.circum = 2 * 3.14 * c1.radius;

   c1.area = 3.14 * c1.radius * c1.radius;

​

   printf("μ›μ˜ xμ’Œν‘œ: %d\n", c.x);

   printf("μ›μ˜ yμ’Œν‘œ: %d\n", c.y);

   printf("μ›μ˜ λ°˜μ§€λ¦„: %d\n", c.radius);

   printf("μ›λ‘˜λ ˆ: %.2f\n", c.circum);

   printf("원면적: %.2f\n", c.area);

​

   printf("μ›μ˜ xμ’Œν‘œ: %d\n", c1.x);

   printf("μ›μ˜ yμ’Œν‘œ: %d\n", c1.y);

   printf("μ›μ˜ λ°˜μ§€λ¦„: %d\n", c1.radius);

   printf("μ›λ‘˜λ ˆ: %.2f\n", c1.circum);

   printf("원면적: %.2f\n", c1.area);

​

   return 0;

}​

--------------------------------------​

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

​

struct Circle

{

   int x;

   int y;

   int radius;

   double circum; //λ‘˜λ ˆ

   double area; //면적

};

​

int main() {

   struct Circle c[3];

​

   for (int i = 0; i < 3; i++) {

       printf("x\n");

       scanf("%d", &c[i].x);

       printf("y\n");

       scanf("%d", &c[i].y);

       printf("λ°˜μ§€λ¦„\n");

       scanf("%d", &c[i].radius);

       c[i].circum = 2 * 3.14 * c[i].radius;

       c[i].area = 3.14 * c[i].radius * c[i].radius;

   }

​



   for (int i = 0; i < 3; i++) {

   printf("%d번째 μ›μ˜ xμ’Œν‘œ: %d\n",i, c[i].x);

   printf("%d번째 μ›μ˜ yμ’Œν‘œ: %d\n", i, c[i].y);

   printf("%d번째 μ›μ˜ λ°˜μ§€λ¦„: %d\n", i, c[i].radius);

   printf("%d번째 μ›λ‘˜λ ˆ: %.2f\n", i, c[i].circum);

   printf("%d번째 원면적: %.2f\n", i, c[i].area);

}

​

   return 0;

}​

​

--------------------------------------​

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

​

struct Sungjuk

{

   char name[20];

   int kor;

   int eng;

   int math;

   double total;

   double avg;

};

​

int main() {

   struct Sungjuk s[3]; //μΈμŠ€ν„΄μŠ€

​

   for (int i = 0; i < 3; i++) {

       printf("이름\n");

       scanf("%s", &s[i].name);

       printf("κ΅­μ–΄\n");

       scanf("%d", &s[i].kor);

       printf("μ˜μ–΄\n");

       scanf("%d", &s[i].eng);

       printf("μˆ˜ν•™\n");

       scanf("%d%*c", &s[i].math);

       s[i].total = s[i].kor + s[i].eng + s[i].math;

       s[i].avg = (double)s[i].total / 3;

       printf("-----");

   }

​



   for (int i = 0; i < 3; i++) {

   printf("%d번째 이름: %s\n",i, s[i].name);

   printf("%d번째 κ΅­μ–΄: %d\n", i, s[i].kor);

   printf("%d번째 μ˜μ–΄: %d\n", i, s[i].eng);

   printf("%d번째 μˆ˜ν•™: %d\n", i, s[i].math);

   printf("%d번째 총점: %.2f\n", i, s[i].total);

   printf("%d번째 평균: %.2f\n", i, s[i].avg);

   printf("-----\n");

}

​

   return 0;

}​

--------------------------------------​​

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

​

typedef struct contact

{

   char name[20];

   char phone[20];

   int ringtone;

}CONTACT;

​

int main() {

   CONTACT arr[] = {

       {"김석진","000-0000-0000",0},

       {"μ „μ •κ΅­","000-0000-0000",0},

       {"박지민","000-0000-0000",0},

       {"김남쀀","000-0000-0000",0},

       {"민윀기","000-0000-0000",0},

       {"μ •ν˜Έμ„","000-0000-0000",0},

       {"κΉ€νƒœν˜•","000-0000-0000",0}

   };

   int size = sizeof(arr) / sizeof(arr[0]);

   int i;

   char name[20];

   int index;

   printf("검색할 이름은?");

   scanf("%s", name);

   index = -1;



   for (int i = 0; i < size; i++) {

       if (strcmp(arr[i].name, name) == 0) {

           index = i;

           break;

      }

   }

​

   if (index >= 0) {

       printf("%s의 μ „ν™”λ²ˆν˜Έ : %s\n", arr[index].name, arr[index].phone);

   }

   else {

       printf("μ°Ύμ„μˆ˜μ—†μŒ");

   }

​

   return 0;

}​

--------------------------------------​​

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

​

typedef struct contact

{

   char name[20];

   char phone[20];

   int ringtone;

}CONTACT;

​

int main() {

   CONTACT ct = { "김석진","000-0000-0000",0 };

   CONTACT* p = &ct;

​

   strcpy(p->phone, "01012345678");

   p->ringtone = 5;

​

   printf("이름: %s\n", p->name);

   printf("μ „λ²ˆ: %s\n", p->phone);

   printf("λ²¨μ†Œλ¦¬: %d\n", p->ringtone);

​

   return 0;

}​

--------------------------------------​​

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

​

typedef struct contact

{

   char name[20];

   char phone[20];

   int ringtone;

}CONTACT;

​

int main() {

   CONTACT ct = { "김석진","000-0000-0000",0 };

   CONTACT* p = &ct;

​

   strcpy(p->phone, "01012345678");

​

   p->ringtone = 5;

   printf("이름\n");

   scanf("%s", p->name);

   printf("μ „λ²ˆ\n");

   scanf("%s", p->phone);

   printf("λ²¨μ†Œλ¦¬\n");

   scanf("%d", &ct.ringtone);

​

​

   printf("이름: %s\n", p->name);

   printf("μ „λ²ˆ: %s\n", p->phone);

   printf("λ²¨μ†Œλ¦¬: %d\n", p->ringtone);

​

   return 0;

}​

--------------------------------------​​

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

​

typedef struct contact

{

   char name[20];

   char phone[20];

   int ringtone;

}CONTACT;

​

int main() {

   CONTACT arr[] = {

       { "A","000-0000-0000",0 },

        { "B","000-0000-0000",0 },

    { "C","000-0000-0000",0 },

     { "D","000-0000-0000",0 },

      { "E","000-0000-0000",0 },

       { "F","000-0000-0000",0 },

   };

   int size = sizeof(arr) / sizeof(arr[0]);

   int i;

   char name[20];

   int index;

   CONTACT* recent = NULL;

​

   while (1) {

       printf("이름 ");

       scanf("%s", name);

       if (strcmp(name, ".") == 0)

           break;

​

       index = -1;

​

​

       for (i = 0; i < size; i++) {

           if (strcmp(arr[i].name, name) == 0) {

               index = i;

               break;

           }

       }

       if (index >= 0) {

           printf("%s의 μ „ν™”λ²ˆν˜Έλ‘œ %s둜 μ „ν™”λ₯Ό κ²λ‹ˆλ‹€\n",

           arr[index].name, arr[index].phone);

           recent = &arr[index];

       }

       else

       {

           printf("μ—†");

​

       }

   }

   if (recent)

       printf("졜근 톡화 : %s %s\n ", recent->name, recent->phone);

   return 0;

}​

--------------------------------------​

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

​

struct student

{

   char name[20];

   char phone[20];

};

void changephone(struct student*sp);

​

int main() {

   

   struct student s;

   printf("이름?");

   scanf("%s", s.name);

   printf("μ „ν™”λ²ˆν˜Έ?");

   scanf("%s", s.phone);

​

   printf("λ³€κ²½μ „ 이름 =%s \n", s.name);

   printf("λ³€κ²½μ „ μ „λ²ˆ =%s \n", s.phone);

   

   changephone(&s);

​

   printf("λ³€κ²½ν›„ μ „λ²ˆ =%s \n", s.phone);

   



   return 0;

}

​

void changephone(struct student* sp) {



   strcpy(sp->phone, "01054625192");

}​

​

 























 


ㅍㅍ