Let us learn C in Code <2>

Now let us finish the the program refers to "Let us learn C in Code <1>". In that article, we  wrote a program to calculate the 1+2=?. The base program as following


main()

{

int a = 1;

int b = 2;

}

Now let us review some conceptions, like key word "int"  which represents integer ,also don't forget that "a" and "b" are variables, as this method if I can define a variable like c in this program, surely we can.

main()

{

int a = 1;

int b = 2;

int c;

}

As above program, we find variables "a " and "b" are different from variable "c" . What's the difference? Yes , variable "c" is not assigned any integer, that 's a bad manner . We just declare variable "c" without an assignment, this is just a variable ,and it doesn't matter, but later ,if u learn the pointer , miss assignment maybe  cause a disaster .Now let us assign a value of 0 to "c", maybe u think that "Why 0 ,other integer number  is ok?" .Surely any integer (as long as it is less then a max number) is ok   and rewrite this program,

main()

{

int a = 1;

int b = 2;

int c = 0;

}

Go on, the equation is 1 + 2 = ?, if we can write them like this "a + b = ?". Before answering this , let us look at the assignment , example  this "a = 1" why not we write "1 =  a" ,because the equal sign "=" means let the right value equal to the left  one . So we can write  "c = a +b ",

main()

{

int a = 1;

int b = 2;

int c = 0;

c = a + b; 

}

Now,we have finished the program ! Can we change the equation "1 + 2 = ? " to  "1.0 + 2.0 = ?" , before we write this program, we should know that there are several keyword in C language .  float  can declare a float variable  char can define a character variable . Please solve this problem , write a program in C to achieve  the equation "1.0 + 2.0 = ?" . Hint used keyword float

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值