Let us learn C in Code <6> _printf()
来源:互联网 发布:直播电影的软件 编辑:程序博客网 时间:2024/06/14 14:42
Now , last chapter told us that if u wanted our pc to output something, we can use the printf() function, but that's just the one thing we want, much more important thing we cared is how the printf() function to output the result of the calculation based on math problem like addition, subtraction, multiplication and division. Surely ,in this chapter, let us learn it. Before we used printf() function, as previous chapter said, the printf() function can output the characters included some special characters like '\n', '\a','\0' etc. If you have write down them in your source files and compile and execute , you may see a jump out windows (if your operation system is windows you will see a windows titled XXX.exe)which output the characters you wrote between the double quotes printf() function. For example, if write like this
main()
{
printf("Hi , everyone!");
printf("Hi , everybody!\nI'm a new line!);
}
It will output like belows
Hi , everyone!
Hi , everybody!
I'm a new line!
From above characters, we know that the '\n' characters is a control character which will cause a new line, if you use '\a' and turn up the volume of our pc , we will listen a sound like "beep" or "boom" , just like this sound i can't describe it well. If you want to hear it, just add some character in your printf() function, but don't forget the double quotes.
Ok, from above code , we know that if we want printf() function to output the result , we just need to add some append commands to the printf() function. Surely, these special command named format code list the below table,
--------------------------------------
Format means
-------------------------------------
%d output decimal
%x output Hexadecimal
%s output string
%c output character
%f output float
%p output pointer
... .....
-------------------------------------
And the base format ,in printf() function like this
printf("The integer is %d",inte);
The 'inte"' is a variable declared before the printf() function, if you define 'inte' is a integer variable and equals 10 .When your program is executed, the output characters include the "10". Now let us code it,
main()
{
int inte = 10;
printf("The integer is %d",inte);
}
It output The integer is 10 , surely you can output the difference result in the same printf() function, just add the format code , then as the same sequence add the variables, as the same time don't forget the comma . Let us output multiple numbers,
main()
{
int inte = 10;
float fnum = 9.5;
char cnum = '!';
printf("The integer is %d, the float one is %f, \n the character one is %c",inte,fnum,cnum);
}
Output
The integer is 10, the float one is 9.50000,
the character one is !
Ok, before over this chapter , please solve the problem equation like this "y = x^2 + 3*x + 8" , if you assign a value x ,it calculate the y , then output the result of the 'y' .Any data type is ok . The "x^2" means two power of x or you can change it to "x*x".
Have a nice day ! If you have any question just leave me a message.
- Let us learn C in Code <6> _printf()
- Let us learn C in Code <5>_printf()_function
- Let us learn C in Code <0>
- Let us learn C in Code <1>
- Let us learn C in Code <2>
- Let us learn C in Code <10>
- Let us learn C in Code <3>_constant
- Let us learn C in Code <4> _data type
- Let us learn C in Code <7> operators
- Let us learn C in Code <8> decision making
- Let us learn C in Code <9> pseudocode
- Let us learn C in Code <10> flowchart
- Let us learn C in Code <11> flowchart while
- Writing endian-independent code in C(Don't let endianness "byte" you)
- API WritePrinter Let us entd1
- C语言随笔_printf输出多行
- 20161213C语言基础08_printf详解
- US zip code
- 杨辉三角
- vim配置及插件安装管理(超级详细)
- 管理oracle 11g RAC 常用命令
- huffman的实现
- 黑马程序员——面试题之交通灯管理系统
- Let us learn C in Code <6> _printf()
- 对象数组操作长方柱类
- CF:358C 暴力DP筛选素数预处理
- wqrehy
- play framework (一)
- fork
- 设计模式介绍之八:职责链模式(Chain of responsibility)
- 强引用、弱引用、软引用、幽灵引用区别
- java反射机制,通过类名获取对象,通过方法名和参数调