문제 1번
#define _CRT_SECURE_NO_WARNINGS // scanf 보안 경고로 인한 컴파일 에러 방지
#include <stdlib.h>
#include <stdio.h>
int main(void) {
int sum = 0;
char a[6];
for (int k = 0; k < 4; k++) {
int i = 0;
printf("Enter an integer string: ");
scanf("%s", a);
i = atoi(a);
sum += i;
}
printf("The total of the values is %d", sum);
return 0;
}
문제 2번
#define _CRT_SECURE_NO_WARNINGS // scanf 보안 경고로 인한 컴파일 에러 방지
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(void) {
char string[300] = {0};
char* ptr = 0;
char alpa = 'a';
printf("Enter three lines of text: ");
gets_s(string, 300);
for (int i = 0; string[i] != NULL; i++) {
if (isupper(string[i])) string[i]= tolower(string[i]);
}
for (alpa = 'a'; alpa <= 'z'; alpa++) {
int cnt = 0;
ptr = strchr(string, alpa);
while (ptr != NULL)
{
cnt++;
ptr = strchr(ptr + 1, alpa);
}
printf("%c: %d\n", alpa, cnt);
}
return 0;
}
문제 3 번
#define _CRT_SECURE_NO_WARNINGS // scanf 보안 경고로 인한 컴파일 에러 방지
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(void) {
char string[80] = {0};
int index[80] = { 0 }, i =0;
char space[] = " ";
char *token;
printf("Enter three lines of text: ");
gets_s(string, 80);
token = strtok(string, space);
while (token != NULL) {
i = strlen(token);
index[i] ++;
token= strtok(NULL, space);
}
for (int k = 1; k < 80; k++) {
if (index[k] != 0) printf("%d words of length %d\n", index[k], k);
}
return 0;
}
문제 4번
#define _CRT_SECURE_NO_WARNINGS // scanf 보안 경고로 인한 컴파일 에러 방지
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(void) {
char temp[50];
char string[11][50] = { {0} };
int result=0;
for (int i = 0; i < 10; i++) {
printf("Enter a string: ");
scanf("%s", string[i]);
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 9 - i; j++) {
result = strcmp(string[j], string[j + 1]);
if (result > 0) {
strcpy(temp, string[j]);
strcpy(string[j], string[j + 1]);
strcpy(string[j + 1], temp);
}
}
}
printf("The strings in sorted order are:");
for (int i = 0; i < 10; i++) {
printf("%s\n", string[i]);
}
return 0;
}