日常C++练习【1】

// 源文件后面必须使.c才能代码运行成功
/*
int main()
{
    printf("he\n");
    return 0;
}

#include <stdio.h>
//求两个整数之和
int main()
{
    int a, b, sum;   //本行使程序的声明部分。定义a,b,sum为整型变量
    a = 123;         //对变量a进行赋值
    b = 456;         //对变量b进行赋值
    sum = a + b;     
    printf("sum is %d \n", sum);
    return 0;
}
*/
/* 
//#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main()
{
    int max(int x, int y);     //对调用函数max的声明
    int a, b, c;
    scanf_s("%d,%d", &a, &b);    // 输入变量a和b的值
    c = max(a, b);             // 调用max函数,将得到的值赋给c
    printf("max=%d/n", c);
    return 0;
}

int max(int x, int y)
{
    int z;
    if (x > y)z = x;
    else z = y;
    return 0;
}


#include <stdio.h>
int main()
{
    printf("Hello,world\n");
    return 0;
}


 // 习题1.  编写一个“hello world”
#include <stdio.h>
int main()
{
    printf("*************\n\n");
    printf("holle world\n\n");
    printf("*************\n");
    return 0;

}


// 2.编写一个c程序,输入a,b,c三个值,输出其中最大的值
#include <stdio.h>
int main()
{
    int a, b, c, max;   //定义变量a,b,c
    printf("please input a,b,c:\n");
    scanf("%d,%d,%d,&a,&b,&c");    //输入变量a,b,c的值
    max = a;
    if (max < b)
        max = b;
    if (max < c)
        max = c;
    printf("The largest number is %d\n", max);
    return 0;
}


// C语言写算法
#include <stdio.h>
int main()
{
    int i, t;    
    t = 1;
    i = 2;
    while (i < 5)
    {
        t = t * i;
        i = i + 1;
    }
    printf("%d\n", t);
    return 0;
}

// N-S
#include <stdio.h>
int main()
{
    float f, c;        //float定义f,c为单精度浮点数型变量
    f = 64.0;
    c = (5.0 / 9) * (f - 32);
    printf("f=%f\nc=%f\n,f,c");
    return 0;
}

// 有1000元,需要存一年,有3种方法:(活期,年利率为r1)(一年定期,年利率r2)(存两次半年定期,年利率r3)
// 计算出一年后按3种方法所得到的本息和
#include <stdio.h>
int main()
{
    float p0 = 1000, r1 = 0.036, r2 = 0.0225, r3 = 0.0198, p1, p2, p3;
    p1 = p0 * (1 + r1);
    p2 = p0 * (1 + r2);
    p3 = p0 * (1 + r3/2) * (1+r3/2);
    printf("p1 = %f\np2 = %f\np3 = %f\n",p1,p2,p3);
    return 0;
}

// 
#include <stdio.h>

int main()
{
    double a, b, c, s, area;  //定义各变量,为双精度浮点数
    a = 3.67;
    b = 5.43;
    c = 6.21;
    s = (a + b + c) / 2;
    area = sqrt(s*(s - a)*(s - b)*(s - c));
    printf("a=%f\tb=%f\tc=%f\n", a, b, c);
    printf("area=%f\n", area);
    return 0;
}

*/

猜你喜欢

转载自blog.csdn.net/m0_58290944/article/details/121255924