C Programming OJ DAY6

/*
实数运算 
注意左对齐 
*/
#include<stdio.h>
#include<stdlib.h>
int main(){
    float a, b, c;
    float v;
    scanf("%f%f%f",&a,&b,&c);
    v=a*b*c;
    printf("%-.3f",v);
/*
%-.3f表示左对齐,尤其要注意-
如果想讲v以总宽度为10的空间进行右对齐且保留三位小数
printf("%10.3f",v); 
*/ 
    return 0;
}
/*
实数运算 Version 2
模块化设计
*/
#include<stdio.h>
#include<stdlib.h>
double cube(double a, double b, double c){
	return a*b*c;
}
int main(){
	double a, b, c;
    printf("Please enter three floating-point numbers separated by spaces: ");
    if (scanf("%lf %lf %lf", &a, &b, &c) != 3) {
        printf("Invalid input. Please enter three floating-point numbers.\n");
        return 1; // Exit with error code
    }
    double v=cube(a,b,c);
    printf("The product is: %.3f\n", v);
    return 0;

}
/*
四则运算
加减乘除取余 
也可以使用switch语句实现 
*/
#include<stdio.h>
#include<stdlib.h>

int main(){
	char str;
	int a,b;
	scanf("%d%c%d",&a,&str,&b);
/*
	switch(op){
		case '+':
			printf("%d+%d=%d\n",a,b,a+b);
			break;
*/ 
	if(str=='+')
	printf("%d%c%d=%d",a,str,b,a+b);
	else if (str=='-')
	printf("%d%c%d=%d",a,str,b,a-b);
	else if (str=='*')
	printf("%d%c%d=%d",a,str,b,a*b);
	else if (str=='/'){
		if(b==0) printf("Error\n");
		else printf("%d%c%d=%d",a,str,b,a/b);
	}
/*
注意在这要讨论一下除数为零的情况 
*/
	else (str=='%');
	printf("%d%c%d=%d",a,str,b,a%b);
	return 0;
}
/*
数位输出 
超级简单的一道题
记得int类型向下取整
*/
#include<stdio.h>
#include<stdlib.h>

int main(){
	int A,a,b,c,d,e;
	scanf("%d",&A);
	a=A/10000;
	b=A%10000/1000;
	c=A%1000/100;
	d=A%100/10;
	e=A%10;
	printf("%d %d %d %d %d",a,b,c,d,e);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值