第一范文网 - 专业文章范例文档资料分享平台

113题经典C程序设计

来源:用户分享 时间:2025/11/19 21:51:51 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

1.输入两个正整数,m和n,求其最大公约数和最小公倍数。 #include void main() {

int hcf(int,int); int lcd(int,int,int); int u,v,h,l;

printf(\input two numbers:\\n\ scanf(\ h=hcf(u,v);

printf(\ l=lcd(u,v,h);

printf(\}

int hcf(int u,int v) {

int t,r; if(v>u)

{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.输入一行字符,分别统计出其中字母、空格、数字和其他字符的个数。 #include

int letter,digit,space,others; void main() {

void count(char[]); char text[80];

printf(\input string:\\n\ gets(text);

printf(\ puts(text); letter=0; digit=0; space=0;

others=0; count(text);

printf(\

}

void count(char str[]) {

int i;

for(i=0;str[i]!='\\0';i++)

if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')) letter++;

else if(str[i]>='0'&&str[i]<='9') digit++;

else if(str[i]==32) space++; else others++; }

3.输入一个正整数求出它是几位数;输出原数和位数。 #include int digit; void main() {

void count(char[]); char text[80];

printf(\input numbers:\\n\ gets(text);

printf(\ puts(text); digit=0;

count(text);

printf(\}

void count(char str[]) {

int i;

for(i=0;str[i]!='\\0';i++)

if(str[i]>='0'&&str[i]<='9') digit++; }

4.输入一个正整数,输出原数并逆序打印出各位数字。 #include

void invertLongInt(long); void main() {

unsigned long iNumber;

printf(\input a number:\\n\ scanf(\

printf(\input number is:%ld\\n\ printf(\ invertLongInt(iNumber); }

void invertLongInt(long x) {

if(x>=0&&x<=9) printf(\ else {

printf(\ invertLongInt(x/10); } }

5.从键盘上输入若干学生的一门课成绩,统计并输出最高成绩和最低成绩及相应的序号,当输入负数时结束输入。

6.从键盘上输入若干学生的一门课成绩,计算出平均分,当输入负数时结束输入。将结果输出。

7.求1!+2!+3!+??+20!,将结果输出。 #include void main()

{

float s=0,t=1; int n;

for(n=1;n<=20;n++) {

t=t*n;

s=s+t; }

printf(\??+20!=%e\\n\}

8.打印以下图案: * *** ***** ******* #include void main() {

int i,j;

printf(\

static const int picture[4][7]={{' ',' ',' ','*'},

{' ',' ','*','*','*'},{' ',' *','*','*','*','*'},{'*','*','*','*','*','*','*'}}; for(i=0;i<=3;i++) {

for(j=0;j<=6;j++)

printf(\ printf(\ } }

9.打印以下图案: * ** *** ****

#include void main() {

int i,j;

printf(\

static const int picture[4][4]={{'*'}, {'*','*'},{' *','*','*'},{'*','*','*','*'}}; for(i=0;i<=3;i++) {

for(j=0;j<=3;j++)

printf(\

printf(\ } }

10.求下列试子的值:1-1/2+1/3-1/4+??+1/99-1/100,将结果输出。 #include void main()

{

float sum=1.0,t,s=1; int i;

for(i=1;i<=100;i++) {

t=s/i;

sum=sum+t; s=-s; }

printf(\??+1/99-1/100=%5.4f\\n\}

11.打印出100~999之间的所有水仙花数。 #include void main()

{

int i,j,k,n;

printf(\~999之间的所有水仙花数 are:\\n\

搜索更多关于: 113题经典C程序设计 的文档
113题经典C程序设计.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0dqcy7kjvl1klhk34qoj_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top