这是有声音的视频,请检查播放器或者声音输出设备。
这次学习的内容:数值运算,数据类型转换
//=======================================
下面请看这样一个例子:
#include <stdio.h>
main()
{
int a=2,b=3,x;
x = a + b;
printf( "%d \n ",x);
printf( "%d \n ", a-b)
x += 100;
printf(" %d \n ",x);
a=1;
printf( "%d \n", b/a );
printf( "%d \n", b%a );
x = a+b*a;
printf( "%d \n", x );
x = (a+b)*a
printf( "%d \n", x );
}
% 表示取余数
对变量自身一些运算 我们使用 += -= *= 等等。
--------------------------------------------
浮点数的一些运算
float price=1.3 , total;
int num=2;
total = price * num;
printf( "%f \n", total );
//===========================================
自增,自减运算符
i++ , ++i , i--, --i
i=1;
printf( "%d \n" , i++ );
printf( "%d \n" , ++i );
注意区别
//=======================================
类型强制转换
#include <stdio.h>
main()
{
int a = 10,b=3;
float c;
c=a/b;
printf( "%f \n", c );
c=(float)a/b;
printf( "%f \n", c );
c=(float)(a/b);
printf( "%f \n", c );
}
-------------------
[17rumen@localhost ~]$ ./a.out
3.000000
3.333333
3.000000
(float)a/b 和 (float)(a/b) 的区别
视频演示就到这里结束了。88
01月 12th, 2012 at 23:00:49 #Kailey
My problem was a wall until I read this, then I smshaed it.
[回复]
01月 13th, 2012 at 17:09:06 #ixbiuyng
nzR4Ov acchcvridmif
[回复]
01月 15th, 2012 at 20:52:34 #lmrsyknso
Q2Ujz9 bpapdjavmojs
[回复]