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

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

 

B C语言实验——输出字符串

C C语言实验——图形输出(字符常量练习)、

均承袭A题 修改输出信息即可 

\n 回车后光标移至下一行行首

\r 回车光标移至本行行首

代码如下:

B题:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("This is a C program.\n");
    return 0;
}

C题:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("#\n##\n###\n####\n#####\n");
    return 0;
}

D C语言实验——求两个整数之和

E A+B Problem

两题由简入繁,前者是后者的基础版

前者代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b;
    a = 123;
    b = 456;
    printf("sum is %d\n",a+b);
    return 0;
}

后者代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{ 
    int a,b;
    scanf("%d %d",&a,&b);//%d 整形  & 取地址符 变量的读取依靠查找其地址,通过地址获取内容
    printf("%d\n",a+b);
    return 0;
}

F C语言实验——交换两个整数的值(顺序结构)

本题除了已有的两变量,另外需要设置中间变量作为过渡。

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    int t;
    t = a;
    a= b;
    b = t;
    printf("%d %d\n",a,b);
    return 0;
}

G C语言实验——逆置正整数

注:

假定一个三位数为n,对其逆置。n \another number  %the third number 

其中 \表示对符号前的数整除取整 % 表示对符号前数整除取余数

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a;
    scanf("%d",&a);
    int b;
    b = 100*(a%10)+10*(a/10%10)+(a/100%10);
    printf("%d\n",b);
    return 0;
}

猜你喜欢

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