511÷292=1余219
292÷219=1余73
219÷73=3
于是得知,5767和4453的最大公约数是73.
辗转相除法适用比较广,比短除法要好得多,它能保证求出任意两个数的最大公约数.
2.输入一行字符,分别统计出其中字母、空格、数字和其他字符的个数。 #include<stdio.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]>='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.输入一个正整数求出它是几位数;输出原数和位数。