//输入两个整数,求两数的平方和并输出
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int a = 0, b = 0;
int sum = 0;
void squares()
{
sum = a * a + b * b;
}
int main( ){
printf("请输入两个整数");
scanf("%d%d", &a,&b);
squares();
printf("%d\n", sum);
system("pause");
}
`
//输入一个圆的半径(r),当r>=0时,计算并输出圆的面积和周长,否则,输出提示信息。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
double r = 0, c = 0, s = 0;
void cir( ) {
c = 3.14 * 2 * r;
}
void square() {
s = 3.14*r*r;
}
int main( ){
printf("请输入半径:");
scanf("%lf", &r);
if (r >= 0){
cir();
square();
printf("%f\n" ,c);
printf("%f\n", s);
}
else
printf("您的输入有误\n");
system("pause");
}
```c
//函数y=f(x)可表示为:2x+1(x<0);0(x=0);2x-1(x>0)
//编程实现输入一个x值,输出一个y值
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int x, y;
void fun1( ){
y=2*x+1;
}
void fun2( ) {
y = 0;
}
void fun3( ) {
y = 2*x - 1;
}
int main( ){
printf("请输入x:");
scanf("%d", &x);
if (x < 0) {
y=2*x+1;
printf("%d", y);
```}
else if (x = 0) {
y=0;
printf("%d", y);
}
else {
y=2*x-1;
printf("%d", y);
}
system("pause");
}
2020.02.02
猜你喜欢
转载自blog.csdn.net/m0_46233999/article/details/104150301
今日推荐
周排行