- 7
- 0
- 约3.56万字
- 约 52页
- 2021-01-14 发布于云南
- 举报
1.输入两个正整数, m 和 n,求其最大条约数和最小公倍数。
#includestdio.h
void main()
{
int hcf(int,int); /* 函数声明 */
int lcd(int,int,int); /* 函数声明 */
int u,v,h,l;
printf(Please input two numbers:\n);
scanf(%d,%d,u,v);
h=hcf(u,v);
printf(H.C.F=%d\n,h);
l=lcd(u,v,h);
printf(L.C.D=%d\n,l);
}
int hcf(int u,int v)
{
int t,r;
if(vu)
{t=u;u=v;v=t;}
while((r=u%v)!=0)
{u=v;v=r;}
return(v);
}
int lcd(int u,int v,int h)
{
return(u*v/h);
}
2.输入一行字符,分别统计出其中字母、空格、数字和其他字符的个数。
#includestdio.h
int letter,digit,space,others;
void main()
{
void count(char[]);
char text[80];
printf(Please input string:\n);
gets(text);
printf(string:\n);
puts(text);
letter=0;
digit=0;
space=0;
others=0;
count(text);
printf(letter:%d,digit:%d,space:%d,others:%d\n,letter,digit,space,others);
}
void count(char str[])
{
int i;
for(i=0;str[i]!=\0;i++)
if((str[i]=astr[i]=z)||(str[i]=Astr[i]=Z))
letter++;
else if(str[i]=0str[i]=9)
digit++;
else if(str[i]==32)
space++;
else
others++;
}
3.输入一个正整数求出它是几位数;输出原数和位数。
#includestdio.h
int digit;
void main()
{
void count(char[]);
char text[80];
printf(Please input numbers:\n);
gets(text);
printf(Numbers:\n);
puts(text);
digit=0;
count(text);
printf(digit:%d\n,digit);
}
void count(char str[])
{
int i;
for(i=0;str[i]!=\0;i++)
if(str[i]=0str[i]=9)
digit++;
}
4.输入一个正整数,输出原数并逆序打印出各位数字。
#includestdio.h
void invertLongInt(long);
void main()
{
unsigned long iNumber;
printf(Please input a number:\n);
scanf(%ld,iNumber);
printf(The input number is:%ld\n,iNumber);
printf(The inverse number is:);
invertLongInt(iNumber);
}
void invertLongInt(long x)
{
if(x=0x=9)
printf(%d\n,x);
else
{
printf(%d,x%10);
invertLongInt(x/10);
}
}
5.从键盘上输入若干学生的一门课成绩,统计并输出最高成绩和最低成绩及相应的序号,当
输入负数时结束输入。
6.从键盘上输入若干学生的一门课成绩,计算出平均分,当输入负数时结束输入。将结果输
出。
7.求 1!+2!+3!+ ,, +20!,将结果输出。
#includestdio.h
void main()
{
float s=0,t=1;
int n;
for(n=1;n=20;n++)
{
t=t*n;
s=s+t;
}
printf(1!+2!+3!+ ⋯ ⋯ +20!\=n%,se);
}
8.打印以下图案: *
***
*****
*******
#includestdio.h
void main()
{
int i,j;
printf(The picture is:\n);
static char picture[4][7]={{ , , ,*},
{ ,
您可能关注的文档
- 垃圾分类知识[共5页].doc
- 垃圾分类诗歌[共10页].doc
- 基本乐理课后练习题[共46页].doc
- 处理客户异议的100条经典话术[共7页].doc
- 复变函数课后习题答案(全)[共130页].doc
- 外科手术切口分类[共3页].doc
- 外贸英语函电课后答案[共77页].doc
- 大学物理下册课后习题答案[共129页].doc
- 大学物理祝之光版--课后习题答案[共62页].doc
- 大学生创新思维培养途径[共20页].doc
- 河北盐山中学等校2025-2026学年上学期高三一模化学试卷(含解析).docx
- 河北正定中学2025-2026学年高一上学期期末考试物理试卷(含解析).docx
- 河北张家口市怀安县2025-2026学年第一学期期末教学综合评价八年级地理试卷(含解析).docx
- 河南安阳市殷都区2025-2026学年第一学期期末教学质量检测七年级地理试卷(含解析).docx
- 河南安阳市滑县2025一2026学年第一学期期末学业质量监测八年级地理试题(含解析).docx
- 河南安阳市林州市2025-2026学年上学期期末考试高一政治试题(含解析).docx
- 河南焦作市武陟县第一中学2025-2026学年高一上学期1月月考语文试卷(含解析).docx
- 河南济源市2025-2026学年上学期期末学业质量调研七年级历史试卷(含解析).docx
- PICC导管并发症的紧急处理与护理.pptx
- 河南鹤壁市2025-2026学年高二上学期期末考试生物试题(含解析).docx
原创力文档

文档评论(0)