Posted on 2007-06-26 16:25
停留的风 阅读(401)
评论(0) 编辑 收藏 所属分类:
C语言程序
求两个数的最大公约数:
#include<stdio.h>
int main(void)
{
int u,v,temp;
printf("Please type in two nonnegative integers.\n ");
scanf("%i%i",&u,&v);
while(v!=0)
{
temp=u%v;
u=v;
v=temp;
}
printf("Their greatest common divisor is %i\n",u);
return 0;
}
将一个数的数字的次序倒转过来输出
#include <stdio.h>
int main(void)
{
int number,right_digit;
printf("Enter your number.\n");
scanf("%i",&number);
while(number!=0)
{
right_digit=number%10;
printf("%i",right_digit);
number=number/10;
}
printf("\n");
return 0;
}
求一个整数的各个位上数的和:
#include <stdio.h>
int main(void)
{
int number,tmp,count=0,no;
printf("Enter a int number: ");
scanf("%i",&number);
no=number;
while(number!=0)
{
tmp=number%10;
count+=tmp;
number=number/10;
}
printf("The count of %i is %i.\n",no,count);
return 0;
}