将算术运算应用于char类型的值

#include <stdio.h>

int main(void)
{
  char first = 'A';
  char second = 'B';
  char last = 'Z';

  char number = 40;

  char ex1 = first + 2;                     // Add 2 to 'A'
  char ex2 = second - 1;                    // Subtract 1 from 'B'
  char ex3 = last + 2;                      // Add 2 to 'Z'

  printf("Character values      %-5c%-5c%-5c/n", ex1, ex2, ex3);
  printf("Numerical equivalents %-5d%-5d%-5d/n", ex1, ex2, ex3);
  printf("The number %d is the code for the character %c/n", number, number);
  return 0;
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266601.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论