第3回演習の解答例

課題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 if(n < m) {
    printf("%d is smaller than %d\n", n, m);
  }
  else{
    printf("%d is equal to %d\n", n, m);
  }
  return 0;
}

課題2

#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;
}

課題3

#include <stdio.h>

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

Updated: