实验1 C语言开发环境使用与数据类型,运算符,表达式

#include<stdio.h>
int main()
{
    printf(" 0\n");
    printf("<H>\n");
    printf("I I\n");
    printf(" 0\n");
    printf("<H>\n");
    printf("I I\n");
    system("pause");
    return 0;
}

 

#include<stdio.h>
int main()
{
    printf(" 0    0\n");
    printf("<H>  <H>\n");
    printf("I I  I I\n"); 
    system("pause");
    return 0;
}

 

 实验2

#include <stdlib.h>
#include <stdio.h>
int main()
{
    int n, sum;
    scanf("%d", &n);
    sum = n/2*(n+1);
    printf("sum = %d\n", sum);
    system("pause");
    return 0;
}

 写法1,2可以满足要求,写法3,4: sum = (n+1)/2*n不能满足要求

 

实验3

#include <stdlib.h>
#include <stdio.h>
int main()
{
    int a, b, t;
    a = 3;
    b = 4;
    printf("a = %d, b = %d\n", a, b);
    t = a;
    a = b;
    b = t;
    printf("a = %d, b = %d\n", a, b);
    system("pause");
    return 0;
}

 代码line12-14实现的功能是交换a与b的数字。

 

实验4

#include <stdlib.h>
#include <stdio.h>
int main()
{
    int x, t, m;
    x = 123;
    printf("x = %d\n", x);
    t = 0;
    m = x % 10;
    t = t *10 + m;
    x = x / 10;
    m = x % 10;
    t = t * 10 + m;
    x = x / 10;
    m = x % 10;
    t = t * 10 + m;
    x = x / 10;
    printf("t = %d\n", t);
    system("pause");
    return 0;
}

第11-23行是为了交换数字的个位,十位,百位

 

实验5

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

int main()
{
    float a, b, c;
    scanf("%f%f%f", &a, &b, &c);
    if(a+b>c&&a-b<c)
        printf("能构成三角形\n");
    else
        printf("不能构成三角形\n");
    system("pause");
    return 0;
}

 

 

实验6

#include <stdlib.h>
#include <stdio.h>
int main()
{
    int year;
    int a;
    year=(10*10*10*10*10*10*10*10*10)/31536000;
    a=(10*10*10*10*10*10*10*10*10)%31536000;
    if(a>182)
        year=year+1;
    else
        year=year;
    printf("10亿秒约等于%d年\n", year);
    system("pause");
    return 0;
}

 

实验7

#include <stdlib.h>


#include <stdio.h>
#include <ctime>
int main()
{
    int n=rand()%40;
    n=n+60;
    printf("n = %d\n", n);
    system("pause");
    return 0;
}

 

 

posted @ 2023-03-06 21:09  刘璎珂  阅读(17)  评论(0编辑  收藏  举报