1004강의 - kyagrd/cprog2018Fall GitHub Wiki
단어를 입력받아 거꾸로 출력하기
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[128]; // 최대 127글자 단어까지
scanf("%s", str);
size_t n = strlen(str);
for (int i=n-1; i>=0; --i)
{
printf("%c", str[i]);
}
printf("\n");
}
#include <stdio.h>
#include <string.h>
#include <stdbool.h> // p.303 bool, true, false
#include <ctype.h>
#define N 10
int main454545646565(void)
{
char c;
// 한 단어만 입력받아 출력하는 프로그램
while ( !isspace(c = getchar()) )
putchar(c);
return 0;
// echo
while ( EOF != (c = getchar()) )
putchar(c);
/*
char ch1, ch2, ch3;
ch1 = getchar(); // scanf("%c", &ch1);
ch2 = getchar();// scanf("%c", &ch2);
ch3 = getchar();// scanf("%c", &ch3);
printf("%c%c%c", ch1,ch2,ch3);
*/
return 0;
}
int max(int x, int y)
{
return (x>y)? x : y;
}
int main879789897(void)
{
int y = 10;
// y의 절대값을 저장할 변수
int absy = (y<0)? -y : y ;
/*
if (y<0)
absy = -y;
else
absy = y;
*/
printf("%d\n", absy);
return 0;
}
int main555(void)
{
int a[N] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int bitsum = 0;
for (int i=0; i<N; ++i)
{
bitsum |= a[i]; // bitsum = bitsum | a[i];
}
if (bitsum)
printf("NOT all zero\n");
else
printf("all zero\n");
return 0;
}
int main444(void)
{
int a[N] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
bool allzero = true;
for (int i=0; i<N; ++i)
{
// if ( a[i] ) allzero = false;
allzero = allzero && !a[i];
}
if (allzero)
printf("all zero\n");
else
printf("NOT all zero\n");
return 0;
}
int main333(void)
{
int a[N] = { 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 };
// 모든 N개의 원소가 0인지 검사
if ( 0 == a[0]
&& 0 == a[1]
&& 0 == a[2]
&& 0 == a[3]
&& 0 == a[4]
&& 0 == a[5]
&& 0 == a[6]
&& 0 == a[7]
&& 0 == a[8]
&& 0 == a[9]
)
printf("all zero\n");
else
printf("NOT all zero\n");
return 0;
}
int main222(void)
{
char str[8]; // 최대 7글자 단어까지
char str2[8]; // 최대 7글자 단어까지
scanf("%7s", str); // 7글자까지만 단어로 받아서 저장
scanf("%7s", str2); // 7글자까지만 단어로 받아서 저장
size_t n = strlen(str);
for (int i=n-1; i>=0; --i)
{
printf("%c", str[i]);
}
printf("\n");
printf("%s\n", str2);
/*
// 137 지정 변경자
printf("%4d\n", 3);
printf("%4d\n", 13);
printf("%4d\n", 213);
printf("%4d\n", 4443);
printf("%4d\n", 54443);
printf("%4d\n", 64443);
printf("%4d\n", -3);
printf("%4d\n", -13);
printf("%4d\n", -213);
printf("%4d\n", -4443);
printf("%4d\n", -54443);
printf("%4d\n", -64443);
*/
return 0;
}