41 提取数中偶数
将一个长整型数的每一位数位上的偶数依次取出来,构成一个新的数,其高低位顺序不变。
#include <stdio.h>
int main()
{
long s;
scanf("%ld",&s);
int i,t=0,w,x=0,m; //w为长整型整数每一位上的数,x为逆序的偶数组合 ,m为x每一位上的数
while(s!=0) //将s中的偶数筛选出来,获得逆序偶数组合x
{
w=s%10;
if(w%2==0)
{
x=x*10+w;
}
s=s/10;
}
while(x!=0) //将顺序调转
{
m=x%10;
t=t*10+m;
x=x/10;
}
printf("%d",t);
return 0;
}
42 判断101~200中的素数数量
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int i,j,m;
for(i=101;i<=200;i++)
{
m=sqrt(i);
for(j=2;j<=m;j++)
if(i%j==0)break;
if(j>m)
printf("%d\n",i);
}
return 0;
}
43 输出杨辉三角形
输出杨辉三角形,其中行数n由用户输入。
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,n; /