首页 > 其他 > 详细

scanf()用法汇总

时间:2014-10-03 01:01:13      阅读:392      评论:0      收藏:0      [点我收藏+]

//***什么情况下使用  &
#include<stdio.h>
int main()
{
 printf("\n\n\t//***什么情况下使用  & \n\n");
 int age;
 float assets;
 char pet[30];
 
 printf("Enter the age ,assets,and favorite pet . \n");
 scanf("%d %f",&age,&assets);/*基本变量名前加 & */
 scanf("%s",pet);// 对于 char 数组不适用 &
    printf("%d $%.2f %s\n",age,assets,pet);
   
    /*使用可变宽度的输出字段*/
   
    printf("\n\n\t/*使用可变宽度的输出字段*/ \n\n");
   
    unsigned width,precision;
 int number = 256;
 double weight = 242.5;
 
 printf("what field width ?\n");
 scanf("%d",&width);
 printf("The number is : %*d:\n",width,number);
 printf("Now enter a width and a precision : \n");
 scanf("%d %d",&width,&precision);
 printf("weight = %*.*f\n",width,precision,weight);
 
 /*跳过输入的头两个整数*/
 printf("\n\n\t/*跳过输入的头两个整数*/\n\n");
 int n;
 printf("Enter three integers : \n");
 scanf("%*d %*d %d",&n);//跳过两个整数,并把第三个整数复制给 n
 printf("The last integer was %d\n",n);
 
   
    return 0;
 
}

scanf()用法汇总

原文:http://www.cnblogs.com/me-ziqiyu/p/4004629.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!