《程序设计基础(B)Ⅰ》实验1-顺序结构程序设计(下)

版权声明:版权问题请加微信:17165380098 备注 版权问题 https://blog.csdn.net/qq_30277453/article/details/82906381

这一篇算重点,相比往年,题要多,且新题集中于本部分

P - 大整数的输入输出

注意long long int 的输入输出方式 一个long 对应一个l 

即 若要求输入输出 long int  %ld

要求输出 int %d

#include <stdio.h>
int main()
{
    long long int a,b;
    scanf("%lld",&a);
    scanf("%lld",&b);
    printf("%lld",a+b);
    return 0;
}

O - 实数的输出和占位

左右对齐用正负号来表现 默认右对齐

#include <stdio.h>
int main()
{
    double n;
    scanf("%lf",&n);
    printf("%lf\n",n);
    printf("*%10.3lf*\n",n);
    printf("*%-10.3lf*\n",n);
    return 0;
}
 

Q - 带’ 和 ”字符的输出

' " 这类特殊字符的输出 需要用\ 

ps:后单引号前的\可以不加 但是为了编程习惯,建议加上

参考:https://blog.csdn.net/jingjingaibiancheng/article/details/52226143

#include <stdio.h>
int main()
{
    char n;
    scanf("%c",&n);
    printf("\'%c\'\n",n);
    printf("\"%c\"\n",n);
    return 0;
}
 

R - '%'字符的输入输出

% 的输入输出 需要用 %% 表示

\的输入输出同理 需要用 \\表示

#include <stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%%%d%%%d",&a,&b,&c);
    printf("%d%%%d%%%d\n",a,b,c);
    return 0;
}
include <stdio.h>
int main()
{
    int a,b,c;
    scanf("%d\\%d\\%d",&a,&b,&c);
    printf("%d\\%d\\%d\n",a,b,c);
    return 0;
}
 

T - 十六进制数输出和占位

%x 十六进制输出(字母小写,大写X为字母大写十六进制格式输出)

%o 八进制输出

参考文献:https://blog.csdn.net/ma451152002/article/details/9062157

#include <stdio.h>
int main()
{
    int a;
    scanf("%d",&a);
    printf("%d\n%x\n%X\n",a,a,a);
    return 0;
}
 

V - 十进制输入输出和其它非空格占位

%08d 默认右对齐 ,缺位补充0 

#include <stdio.h>
int main()
{
    int a;
    scanf("%d",&a);
    printf("%d\n*%08d*\n*%-8d*\n",a,a,a);
    return 0;
}

剩余几题,大家自行编写,原理与前文所述相仿。

猜你喜欢

转载自blog.csdn.net/qq_30277453/article/details/82906381