/*
实数运算
注意左对齐
*/
#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;
}