随机输入一个整数,若整数中含数字6则输出yes!,否则输出no!。第二题:
用rand随机函数产生一个整数,然后逐位判断是否为6
用数字循环与10取模,判断是否包含6,
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int n,t;
srand(time(0));
n = rand();
while(n)
{
t = n%10;
if(t==6)
{
printf("yes");
break;
}
n/=10;
}
if(n==0)
printf("no");
return 0;
}