自由尋覓快樂別人從沒法感受

0%

实验目的:

(1) 理解常用运行符的功能, 优先级和结合性
(2) 熟练掌握算术表达式的求值规则
(3) 熟练掌握算数表达式的求值规则
(4) 理解自加, 自减运算符和逗号运算符
(5) 掌握关系表达式和逻辑表达式的求值

实验内容: (1)整数相除

主要代码:

1
2
3
4
5
6
7
8
9
10
11
# include <stdio.h>  
int main ()
{
float a =5 , b = 7 , c =100;
float d,e,f;
d = a/b*c;
e = a*c/b;
f = c/b*a;
printf("d=%.5f,e=%.5f,f=%.5f \n\n",d,e,f);
return 0;
}
阅读全文 »

题目: 求一个四位数的倒叙输出

主要代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# include <stdio.h>  
int main ()
{
int a,b,c,d,e,f;
printf("请输入一个四位数: \n\n");
scanf("%d",&a);
if (a>=1000 && a<=9999)
{
b = a/1000;
c = a/100 - b*10;
d = a/10 - b*100 - c*10;
e = a - b*1000 - c*100 - d*10;
printf("千位数: %d \n\n",b);
printf("百位数: %d \n\n",c);
printf("十位数: %d \n\n",d);
printf("个位数: %d \n\n",e);
f = e*1000 + d*100 + c*10 + b;
printf("倒序输出后: %d \n\n",f);
}
else
{
printf("格式错误!请输入1000到9999的数字! \n\n");
}
return 0;
}
阅读全文 »

题目:编程求一个三位数的个位、十位和百位

主要代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# include <stdio.h>  

int main (void)
{
int a,b,c,d;
printf("请输入一个三位数:\n");
scanf("%d",&a);
if (a>=100 && a<1000)
{
b = a/100;
c = a/10 - b*10;
d = a - b*100 - c*10;
printf("百位数:%d \n\n",b);
printf("十位数:%d \n\n",c);
printf("个位数:%d \n\n",d);
}
else
{
printf("error!\n");
}
return 0;
}
阅读全文 »

题目:从键盘上输入两个数, 求两个数的和、差、积与商

主要代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# include <stdio.h>  
int add (float ,float);
int multi (float ,float);
int cut (float ,float);
float division(float ,float);
int main (void)
{
float x,y;
printf("press x,y: \n\n");
scanf("%f%f",&x,&y);
float s1,s2,s3,s4;
s1 = add(x,y);
s2 = multi(x,y);
s3 = cut(x,y);
s4 = division(x,y);
printf("add result:%f \n\n",s1);
printf("multi result:%f \n\n",s2);
printf("cut result:%f \n\n",s3);
printf("division result:%f \n\n",s4);
return 0;
}

int add (float a ,float b)
{
float result;
result = a + b;
return result;
}

int multi (float a ,float b)
{
float result;
result = a * b;
return result;
}

int cut (float a ,float b)
{
float result;
result = a - b;
return result;
}

float division (float a ,float b)
{
float result;
result = (float)a/b ;
return result;
}
阅读全文 »

题目:输入三个整数,求它们的和与积

主要代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# include <stdio.h>  
int add (int ,int ,int);
int multi (int ,int ,int);
int main (void)
{
int x,y,z;
printf("press x,y,z \n\n");
scanf("%d%d%d",&x,&y,&z);
int s1,s2;
s1 = add(x,y,z);
s2 = multi(x,y,z);
printf("add result:%d \n\n",s1);
printf("multi result:%d \n\n",s2);
return 0;
}
int add (int a ,int b ,int c)
{
int result;
result = a + b + c;
return result;
}
int multi (int a ,int b ,int c)
{
int result;
result = a * b * c;
return result;
}
阅读全文 »