ページ

2019年11月16日土曜日

簡単なヌメロンのプログラム

暇だったんでヌメロンのプログラムを作成してました
cファイルはここに置いておきます。
Google Driveへ飛びます

プログラム

#include<stdio.h>
#include<time.h>
#include<stdlib.h>

int main(void)
{
int a=0,n=0,h,b,n1,n2,n3;

do{
srand((unsigned)time(NULL));
n= rand()%999+1;

n3 = n / 100; //初期値の3桁目の値
n = n - n3 * 100;
n2 = n / 10; //初期値の2桁目の値
n1 = n % 10; //初期値の1桁目の値
}while(n3 == n2 || n2 == n1 || n1 == n3);

do{
h=0;
b=0;
printf("number:");
scanf("%d",&a);
int a3 = a / 100; //3桁目の値
a = a - a3 * 100;
int a2 = a / 10; //2桁目の値
int a1 = a % 10; //1桁目の値

if(a3 == n3){ //Hの場合hに1を足す
h += 1;
}
else if(a3 == n2 || a3 == n1){ //Bの場合bに1を足す
b += 1;
}

if(a2 == n2){
h += 1;
}
else if(a2 == n3 || a2 == n1){
b += 1;
}

if(a1 == n1){
h += 1;
}
else if(a1 == n2 || a1 == n3){
b += 1;
}

printf("H%d B%d¥n",h,b);
}while(h != 3); //hが3以外の場合は継続

return 0;
}

まあ一人で楽しむようです。
アイテムありのプログラムもそのうち作ります。(多分)
まあこんなところでノシ


にほんブログ村に参加しています。


↓よかったらクリックお願いします↓

にほんブログ村 その他趣味ブログ 電子工作へ


0 件のコメント:

コメントを投稿