- 13
- 0
- 约小于1千字
- 约 15页
- 2020-10-22 发布于广东
- 举报
实 验 报 告;2;3;4;代码:#includestdio.h
#includestdlib.h #includetime.h int add(int x,int y);6;7;8;9;题目 2:自定义一个求 n 的阶乘的函数。在主函数中调用该
函数,当用户输入非负数的时候,程序输出该数的阶乘;当 用户输入负数的时候,程序退出。
流程图:;代码:#includestdio.h
int main()
{
int a,s;
int jiecheng(int b);
printf(please input a number: ); scanf(%d,a);
if(a=0)
{
s=jiecheng(a); printf(%d!=%ld\n,a,s);
};else
printf(Input error!\n);
}
int jiecheng(int b)
{
int i,s=1; if(b==0)
s=0;
else
{
for(i=1;i=b;i++) s*=i;
}
return s;
}
实验结果:;题目 3:自定义一个函数,判断字符是数字、小写字母、大
写字母还是其他,返回值为 0 时,表示数字;为 1 时,表
示小写字母;为 2 时,表示大写字母;为 3 时表示其他。 在主函数中调用该函数,判断用户输入的字符是哪一种,并 输入“是数字”、 “是小写字母”、“是大写字母”、“其他”; 当用户输入“#”的时候,程序退出
流程图:;14;else if(a!=#)
{ return 3;}
}
运行结果:
原创力文档

文档评论(0)