C语言第四章程序设计实训
作者:互联网
1.定义三个整型变量m=23,n=5,a;
2.a等于表达式!m+m%n;
3.输出a此时a为表达式的值
#include<stdio.h>
int main() {
int m=23, n=5, a;
a = !m + m % n;
printf("%d",a);
return 0;
}
1.定义整型变量x=1,y=2;
2.使用if判断x等于y并且负负x>0
3.输出x
#include<stdio.h>
int main() {
int x = 1, y = 2;
if ((x>y)&&(--x>0)) {
}
printf("%d", x);
return 0;
}
1.定义整型变量a=0,b=3,c=2;
2.使用if判断a+1并且b+1判断正确c减1
3.判断a+==6或者b–判断成功c++
4.输出abc
#include<stdio.h>
int main() {
int a = 0, b = 3, c = 2;
if (a++ && b++) {
c--;
}
else if (a + 1 == 6 || b--) {
c++;
}
printf("%d,%d,%d",a,b,c);
return 0;
}
1.定义四个整型变量a=8,b=4,c=2,d;
2.d等于表达式sqrt(fabs(a) != 4 * a / b / c);
3.输出d此时d等于以上表达式
#include<stdio.h>
#include<math.h>
int main() {
int a = 8, b = 4, c = 2, d;
d = sqrt(fabs(a) != 4 * a / b / c);
printf("%d", d);
return 0;
}
1.定义三个整型变量a=0,b=0,c=0;
2.使用if判断a++并且b+=a或者++c
3.2判断成功输出a,b,c;
#include<stdio.h>
int main() {
int a = 0, b = 0, c = 0;
if (a++&&(b+=a)||++c) {
printf("%d,%d,%d\n",a,b,c);
}
return 0;
}
1.定义常量N等于8
2.定义两个整型变量x等于2,z等于1
3.定义一个小数变量y等于1.2
4.使用switch语句
5.如果x等于2,y+1然后结束
6.如果x等于字符0,y=3
7.输出y
#include<stdio.h>
#define N 8
int main() {
int x = 2, z = 1;
double y = 1.2;
switch (x) {
case 2:
y++;
break;
case '0':
y = 3;
}
printf("%lf",y);
}
1.定义四个整型变量x,y,a,b;
2.输入x和y的值
3.if判断x是否大于y如果大于y进入4否则跳转5
4.a等于x,b等于y
5.a等于y,b等于x
6.输出a和b
#include<stdio.h>
int main() {
int x, y, a, b;
scanf_s("%d%d",&x,&y);
if (x>y) {
a = x;
b = y;
}
else {
a = y;
b = x;
}
printf("%d,%d",a,b);
return 0;
}
1.定义两个整型变量x,y
2.输出“请输入”
3.输入x的值
4.判断x是否大于等于0判断正确y等于1否则y等于-1
5.输出y
#include<stdio.h>
int main() {
int x, y;
printf("请输入:");
scanf_s("%d",&x);
if (x>=0) {
y = 1;
}
else {
y = -1;
}
printf("%d",y);
}
1.定义三个整型变量a=3,b=3,c=2;
2.判断不等于a并且不等于b并且c判断正确跳转3否则跳转4
3.输出a
4.输出b
#include<stdio.h>
int main() {
int a = 3, b = 3, c = 2;
if (!a&&!b&&c) {
printf("a");
}
printf("b");
return 0;
}
1.定义一个整型变量n等于8;
2.n等于n余n-2
3.输出n
#include<stdio.h>
int main() {
int n = 8;
n %= n - 2;
printf("%d",n);
return 0;
}
1.定义三个整型变量x,b=2,a=3;
2.x等于a大于b++判断正确跳转3否则跳转4
3.a++
4.b++
5.输出x,a,b
#include<stdio.h>
int main() {
int x, b = 2,a=3;
x = a > b++ ? (a++) : (b++);
printf("%d,%d,%d",x,a,b);
return 0;
}
1.定义三个整型变量x=4,y=3,x=5;
2.判断x是否大于y判断正确跳转3
3.z等于x,x等于y,y等于z
#include<stdio.h>
int main() {
int x = 4, y = 3, z = 5;
if (x>y) {
z = x;
x = y;
y = z;
}
printf("%d,%d,%d",x,y,z);
return 0;
}
1.定义三个整型变量a=0,b=2,c;
2.b等于负负a或者++b
3.输出b
#include<stdio.h>
int main() {
int a = 0, b = 2, c;
b = --a || ++b;
printf("%d",b);
return 0;
}
1.定义两个变量s,x=1;
2.s等于x<=0判断正确跳转3否则跳转4
3.s等于-1
4.判断x是否等于0判断正确跳转5否则跳转6
5.s等于0
6.s等于6
7.输出s
#include<stdio.h>
int main() {
int s, x=1;
s = x <= 0 ? (-1) : (x == 0) ? (0) : (1);
printf("%d",s);
return 0;
}
1.定义三个变量x=0,y=1,z=10;
2.判断x是否真假判断正确跳转3
3.判断y是否真假判断正确z等于20;否则跳转4
4.z等于30;
5.输出z的值
#include<stdio.h>
int main() {
int x = 0, y = 1, z = 10;
if (x) {
if (y) {
z = 20;
}
else {
z = 30;
}
}
printf("%d\n",z);
return 0;
}
1.定义两个整型变量i=1,n=0;
2.使用switch语句
3.如果i等于1的话
4.如果i等于2的话n+1
5.如果i等于3的话n+1
6.输出n
#include<stdio.h>
int main() {
int i = 1, n = 0;
switch (i) {
case 1:
case 2:n++;
case 3:n++;
}
printf("%d",n);
return 0;
}
1.定义三个整型变量x=0,y=0,z=0;
2.判断x++并且y+=x或者++z
3.输出x,y,z的值
#include<stdio.h>
int main() {
int x= 0, y = 0, z = 0;
if (x++&&(y+=x)||++z) {
printf("%d,%d,%d\n",x,y,z);
}
return 0;
}
1.定义变量a
2.输入变量a
3.判断a余2是否等于0判断正确跳转4判断错误跳转5
4.输出偶数
5.输出奇数
#include<stdio.h>
int main() {
int a;
scanf_s("%d",&a);
if (a%2==0) {
printf("偶数");
}
else {
printf("奇数");
}
return 0;
}
#include<stdio.h>
#include <math.h>
int main()
{
double a, b, c, x1, x2, r, i, delt;
printf("请输入:");
scanf_s("%lf%lf%lf",&a,&b,&c);
if (fabs(a)<=1e-6) {
printf("1234");
}
else {
delt = b * b - 4 * a * c;
if (fabs(delt) <= 1e-6) {
printf("%8.4f\n", -b / (2 * a));
}
else {
if (delt > 1e-6) {
x1 = (-b + sqrt(delt)) / (2 * a);
x2 = (-b - sqrt(delt)) / (2 * a);
printf("%8.4f和%8.4f", x1, x2);
}
else {
r = -b / (2 * a);
i = sqrt(-delt) / (2 * a);
printf("%8.4f+%8.4f\n", r, i);
printf("%8.4f-%8.4f\n", r, i );
}
}
}
return 0;
}
1.定义两个小数类型的变量a,b
2.定义一个字符变量c
3.输入a,b,c
4.使用switch语句
5.如果c等于+的话输出a+b然后结束
6.如果c等于-的话输出a-b然后结束
7.如果c等于的话输出ab然后结束
8.如果c等于/判断b是否等于0判断正确输出除数不能为零否则的输出a/b
#include<stdio.h>
int main() {
double a, b;
char c;
scanf_s("%lf%c%lf",&a,&c,1,&b);
switch (c) {
case'+':
printf("%lf%c%lf=%lf", a, c, b, a + b);
break;
case'-':
printf("%lf%c%lf=%lf", a, c, b, a - b);
break;
case'*':
printf("%lf%c%lf=%lf", a, c, b, a * b);
break;
case'/':
if (b==0) {
printf("除数不能为零!");
}
else {
printf("%lf%c%lf=%lf", a, c, b, a / b);
}
break;
default :
printf("输入错误");
}
return 0;
}
1.定义两个小数型变量salary,sale;
2.输入sale的值
3.判断sale是否小于10000判断正确salary等于1000否则跳转4
4.判断sale小于20000判断正确salary等于1000+sale减10000乘以0.05否则跳5
5.判断sale小于50000判断正确salary等于1000+sale减20000乘以0.06否则跳6
6.判断sale小于100000判断正确salary等于1000+sale减50000乘以0.07否则跳7
7.salary等于1000+sale减100000乘以0.08
#include<stdio.h>
int main() {
double salary, sale;
scanf_s("%lf",&sale);
if (sale<10000) {
salary = 1000;
}
else if (sale>10000&&sale < 20000) {
salary = 1000 + (sale - 10000) * 0.05;
}
else if (sale>20000&&sale < 50000) {
salary = 1000 + (sale - 20000) * 0.06;
}else if (sale>50000&&sale < 100000) {
salary = 1000 + (sale - 50000) * 0.07;
}
else {
salary = 1000 + (sale - 100000) * 0.08;
}
printf("%.3f",salary);
return 0;
}
标签:main,int,printf,sale,C语言,实训,等于,程序设计,include 来源: https://blog.csdn.net/qq_61961358/article/details/121869657