第3回 (5/20) 演習の解答例

課題1

#include <stdio.h>

int main(void)
{
  int n, m;
  scanf("%d %d", &n, &m);
  if (n >= m) {
    printf("%d is larger than %d\n", n, m);
  } else {
    printf("%d is smaller than %d\n", n, m);
  }
  return 0;
}

課題2

#include <stdio.h>

int main(void)
{
  float n, m;
  scanf("%f %f", &n, &m);
  if (n >= m) {
    printf("%f is larger than %f\n", n, m);
  } else {
    printf("%f is smaller than %f\n", n, m);
  }
  return 0;
}

課題3

#include <stdio.h>

int main()
{
  int year;
  scanf("%d", &year);
  if (year%4==0 && year%100!=0 || year%400==0)
  {
    printf("%d is a leap year\n", year);
  }
  else
  {
    printf("%d is a common year\n", year);
  }
  return 0;
}

課題4

#include <stdio.h>

int main()
{
  int c;
  c=getchar();
  if (c>='a' && c<='z')
  {
    putchar(c-'a'+'A');
  }
  else
  {
    putchar(c);
  }
  putchar('\n');
  return 0;
}

Updated: