C语言的编程问题,帮帮小弟,谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/28 04:37:37
1.输入两个正整数M和N,求其最大公约数和最小公倍数
2.输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数
3.打印出所有的"水仙花数"
4.一个小球从100米高空落下,每次落地后反跳回原来高度的一半,再落下,求在第十次落地时,共经过了多少米?第十次反弹多高?
5.求一个3*3矩阵的两条对角线元素之和
用C语言给出程序,谢谢

1.
main()
{
int a,b,num1,num2,temp;
printf("please input two numbers:\n");
scanf("%d,%d",&num1,&num2);
if(num1
{ temp=num1;
num1=num2;
num2=temp;
}
a=num1;b=num2;
while(b!=0)/*利用辗除法,直到b为0为止*/
{
temp=a%b;
a=b;
b=temp;
}
printf("gongyueshu:%d\n",a);
printf("gongbeishu:%d\n",num1*num2/a);
}
2.
#include "stdio.h"
main()
{char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:char=%d spa