๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ C Programming/๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ_๊ฐœ์ • 3ํŒ

[๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ - ๊ฐœ์ • 3ํŒ] 10์žฅ Programming ํ’€์ด (1)

by A Lim Han 2023. 1. 24.

# 10์žฅ Programming ํ’€์ด (1)

 

 

413p_1๋ฒˆ)

#include <stdio.h>
#include <string.h>

int main() 
{
    char string_array[10];
    char cnt_array[26] = { 0 };

    printf("ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
    gets_s(string_array, 10);

    for (int k = 'a', i = 0; i < strlen(string_array) / sizeof(char); k++, i++) 
    {
        cnt_array[string_array[i] - 97]++;
    }

    for (int p = 'a', i = 0; i < 26; p++, i++) 
    {
        if (cnt_array[i] != 0) 
        {
            printf("%c๋ฌธ์ž๊ฐ€ %d๋ฒˆ ๋“ฑ์žฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.\n", p, cnt_array[i]);
        }
        else 
        {
            continue;
        }
    }

    return 0;
}

์ฐธ๊ณ :&nbsp;https://covetknowledge.tistory.com/40

 

 

 

 

413p_2๋ฒˆ)

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
	int i = 0;
	char array[100];

	printf("ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	gets_s(array, 100);

	printf("๋Œ€๋ฌธ์ž ์ถœ๋ ฅ: ");

	while (1) 
	{ 
		if (array[i] == '\0')
		{
			break;
		}

		printf("%c", toupper(array[i])); 

		i++;
	}
	
	return 0;
}

 

 

 

 

413p_3๋ฒˆ)

#include <stdio.h>
#include <string.h>

int main() 
{
    char array[100];

    printf("ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
    gets_s(array, 100);

    printf("๊ณต๋ฐฑ์ด ์ œ๊ฑฐ๋œ ํ…์ŠคํŠธ: ");

    for (int i = 0; i < strlen(array); i++) 
    {
        if (array[i] == ' ' && array[i + 1] == ' ') 
        {
            continue;
        }

        printf("%c", array[i]);
    }

    return 0;
}

 

 

 

 

413p_4๋ฒˆ)

#include <stdio.h>
#include <string.h>

int main()
{
	char array[100];

	printf("ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	gets_s(array, 100);

	printf("์ตœ์ข… ํ…์ŠคํŠธ: ");
	for (int i = 0; i < strlen(array); i++)
	{
		if (array[i] == 'a' || array[i] == 'e' || array[i] == 'i' || array[i] == 'o' || array[i] == 'u')
		{
			array[i] = ' ';
		}
		else
		{
			printf("%c", array[i]);
		}
	}

	return 0;
}

 

 

 

 

414p_5๋ฒˆ)

#include <stdio.h>
#include <string.h>

int main()
{
	int ok = 0;
	char chiper[100];

	while (ok < 1)
	{
		int number = 0;	   // ์ˆซ์ž ๊ฐœ์ˆ˜
		int char_1 = 0;    // ์˜๋ฌธ ์†Œ๋ฌธ์ž ๊ฐœ์ˆ˜
		int char_2 = 0;    // ์˜๋ฌธ ๋Œ€๋ฌธ์ž ๊ฐœ์ˆ˜

		printf("์•”ํ˜ธ๋ฅผ ์ƒ์„ฑํ•˜์‹œ์˜ค: ");
		gets_s(chiper, 100);

		for (int i = 0; i < strlen(chiper); i++)
		{
			if ('0' <= chiper[i] && chiper[i] <= '9')
			{
				number++;
			}
			else if ('a' <= chiper[i] && chiper[i] <= 'z')
			{
				char_1++;
			}
			else if ('A' <= chiper[i] && chiper[i] <= 'Z')
			{
				char_2++;
			}
		}

		if (number > 0 && char_1 > 0 && char_2 > 0)
		{
			printf("์ ์ •ํ•œ ์•”ํ˜ธ์ž…๋‹ˆ๋‹ค.\n");
			ok++;
		}
		else if (number == 0)
		{
			printf("์•”ํ˜ธ๋Š” ์ˆซ์ž๋ฅผ ํฌํ•จํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์•”ํ˜ธ๋ฅผ ๋‹ค์‹œ ์ƒ์„ฑํ•˜์„ธ์š”.\n");
		}
		else if (char_1 == 0)
		{
			printf("์•”ํ˜ธ๋Š” ์˜๋ฌธ ์†Œ๋ฌธ์ž๋ฅผ ํฌํ•จํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์•”ํ˜ธ๋ฅผ ๋‹ค์‹œ ์ƒ์„ฑํ•˜์„ธ์š”.\n");
		}
		else if (char_2 == 0)
		{
			printf("์•”ํ˜ธ๋Š” ์˜๋ฌธ ๋Œ€๋ฌธ์ž๋ฅผ ํฌํ•จํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์•”ํ˜ธ๋ฅผ ๋‹ค์‹œ ์ƒ์„ฑํ•˜์„ธ์š”.\n");
		}
	}

	return 0;
}

 

 

 

 

414p_6๋ฒˆ)

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
	char array[100];

	printf("ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	gets_s(array, 100);

	if ('a' <= array[0] || array[0] <= 'z')	// ์†Œ๋ฌธ์ž --> ๋Œ€๋ฌธ์ž
	{
		array[0] = toupper(array[0]);
	}

	printf("๊ฒฐ๊ณผ ํ…์ŠคํŠธ ์ถœ๋ ฅ: ");

	for (int k = 0; k < strlen(array); k++)
	{
		printf("%c", array[k]);
	}

	printf(".\n");

	return 0;
}