【C言語 入門】変数の値の表示

  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // your code goes here
  5.  
  6. int a,b,c;
  7.  
  8. a=10;
  9. b=15;
  10.  
  11. c=a+b;
  12.  
  13. printf("%dたす%dは%dです。\n",a,b,c);
  14.  
  15. return 0;
  16. }

 

出力結果

10たす15は25です。

 

メモ

変数aに10を代入

変数bに15を代入

 

変数cにaとbを足して代入

 

以下の記述でも同じ出力結果となる。

 

 

  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // your code goes here
  5.  
  6. int a,b,c;
  7.  
  8. a=10;
  9. b=15;
  10.  
  11. printf("%dたす%dは%dです。\n",a,b,a + b);
  12.  
  13. return 0;
  14. }

 

出力結果

0.500000 + 10.500000 = 11.000000
cの値は215でこれに11を加えると226になります。
eには"A"が代入されています。