Let us learn C in Code <6> _printf()

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. 





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值