當前位置:首頁 » 編程語言 » c語言畫狗代碼
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言畫狗代碼

發布時間: 2023-04-03 14:29:30

1. 小狗給小貓吃糖c語言編程

按照你說的寫了1——0000的,演算法相同,到1000000應該要解決一個數據類型的問題,好久沒用C寫應用程序了。呵呵。#include。#include。int isSushu(long int x);。long int caice(long int cai,long int real,long int re_num);。void main()。{。 int i = 0;。 int dog_counter;小狗的糖果數目。 int counter_sushu = 0;1-0000之間的素數數目。 int nosushu_counter;非素數。 int caice_num = 0;小貓猜測的數 int caice_counter = 0;猜測的次數。。。printf("請輸入要小狗的糖果數目1---0000\n");。scanf("%d",dog_counter);。。for(i = ;ii++)。{。if(isSushu(i)==1)。{。如果是素數。counter_sushu++;。}。}。。nosushu_counter = 0000-counter_sushu;。。wle(1)。{。printf("請輸入小貓猜測的數\n");。 scanf("%d",。caice_counter++;。nosushu_counter = caice(caice_num,dog_counter,nosushu_counter);。if(caice_num == dog_counter)。{。break;。}。} printf("猜測的次數是%d\n",caice_counter);。。}。如果是素數則返回1,否則返回0。int isSushu(long int x)。{。int i = ;。for(i=;ii++)。{。if(x%i == 0)。return 0;。}。return 1;。}。long int caice(long int cai,long int real,long int re_num)。cai為猜測的數,real為真實數目,re_num為剩下需要猜的次數。{。if(cai == real)。{。printf("糖果一共有%d個,猜對了\n",cai);。}。else if(caireal)。{。printf("猜的數目小於真實數目,請小貓重新猜測\n");。re_num = re_num-cai;。}。else if(caireal)。{。printf("猜的數目大於真實數目,請小貓重新猜測");。re_num = cai-1;。}。return re_num;。}。

2. 用switch判斷年份屬相,C語言編程: 已知2015年是羊年,編程實

提起用switch判斷年份屬相,大家都知道,有人問C語言編程: 已知2015年是羊年,編程實現,輸入任意年份,輸出該年屬相。(使用switch,另外,還有人想問設計一個程序,輸入1900年以後的任意一個年份,計算該年的生肖.(用select case語句做),你知道這是怎麼回事?其實java中如何用switchcase語句判斷年份對應的生肖?…,下面就一起來看看C語言編程: 已知年是羊年,編程實現,輸入任意年份,輸出該年屬相。(使用switch,希望能夠幫助到大家!

用switch判斷年份屬相

1、C語言編程: 已知年是羊年,編程實現,輸入任意年份,輸出該年屬相。(使用switch

int main()    int year;

    printf(“請輸入年份:”);

    scanf(“%d”,&year);

    year=(year-)%12;

    if(year<0) year+=12;

    switch(year)

    {

        case 0:printf(“今年是羊年!n”);break;

        case 1:printf(“今年是猴年!n”);break;

        case 2:printf(“今年年!n”);break;

        case 3:printf(“今年是狗年!n”);break;

        case 4:printf(“今年是豬年!n”);break;

        case 5:printf(“今年是鼠年!n”);break;

        case 6:printf(“今年是牛年!n”);break;

        case 7:printf(“今年是虎年!n”);break;

        case 8:printf(“今年是兔年!n”);break;

        case 9:printf(“今年是龍年!n”);break;

        case 10:printf(“今年是蛇年!n”);break;

        case 11:printf(“今年是馬年!n”);break;

    }

    return 0;

2、設計一個程序,輸入年以後的任意一個年份,計算該年的生肖.(用select case語句做)

PrivateSubCommand1_Click()

Dimy%,x%,s$

y=Val(InputBox(“輸入年以後的任意一個年份”))

java中如何用switchcase語句判斷年份對應的生肖?…

Ify>=Then

x=(y-)

SelectCasex

Case0

s=”鼠”

Case1

s=”牛”

Case2

s=”虎”

Case3

s=”兔”

Case4

s=”龍”

Case5

s=”蛇”

Case6

s=”馬”

Case7

s=”羊”

Case8

s=”猴”

Case9

s=”雞”

s=”狗”

s=”豬”

EndSelect

MsgBoxy&”年是”&s&”年”

Else

MsgBox”輸入錯誤,年份必須大於等於”

EndIf

EndSub

以上就是與C語言編程: 已知年是羊年,編程實現,輸入任意年份,輸出該年屬相。(使用switch相關內容,是關於C語言編程: 已知2015年是羊年,編程實現,輸入任意年份,輸出該年屬相。(使用switch的分享。看完用switch判斷年份屬相後,希望這對大家有所幫助!

3. 51單片機 c語言看門狗程序怎麼寫

看門狗在51單片機電路里的作用是防止程序 「跑飛」、「死機」後,系統不和穗動作,而採取復位的辦法「喚醒」系統段棚帆。

89S51、89S52系列單片機自帶有看門狗功能,片內數據區A6H寄存器具有看門狗功能,使用很簡單:

#include<reg51.h>
...
sfr WDTRST = 0xA6;
...
void main()
{
WDTRST=0x1E;;//初始化看門狗
WDTRST=0xE1;//初始化看門狗
for(;;)
{
WDTRST=0x1E;;//喂狗指令

WDTRST=0xE1;//喂狗指令
}

}
可見,你只要在程序的大循環體內加一條喂狗指令就行。但這種看門狗功能有限,不是很可靠的,握雹它依靠晶振工作,一旦晶振不起振,就無效了。

實踐中多採用外部看門狗的方法,可以選用的晶元很多:MAX708、MAX813
、X25045.....具體編程就要看晶元的參考資料了。

例如:X25045是SPI匯流排的看門狗晶元,復位端和單片機復位端連接,SPI數據輸入你可以選擇合適的IO介面。

WREN 0x06 設置寫允許位
WRDI 0x04 復位寫允許位
RDSR 0x05 讀狀態寄存器
WRSR 0x01 寫狀態寄存器
READ 0x03/0x0b 讀操作時內部EEPROM頁地址
WRITE 0x02/0x0a 寫操作時內部EEPROM頁地址

#include <reg51.h>
sbit CS= P2^7;
sbit SO= P2^6;
sbit SCK= P2^5;
sbit SI= P2^4;
#define WREN 0x06 //
#define WRDI 0x04 //
#define RDSR 0x05 //
#define WRSR 0x01 //
#define READ0 0x03 //
#define READ1 0x0b //
#define WRITE0 0x02 //
#define WRITE1 0x0a //
#define uchar unsigned char
uchar ReadByte() //read a byte from device
{
bit bData;
uchar ucLoop;
uchar ucData;
for(ucLoop=0;ucLoop<8;ucLoop++)
{
SCK=1;
SCK=0;
bData=SO;
ucData<<=1;
if(bData)
{ ucData|=0x01; }
}
return ucData;
}
void WriteByte(uchar ucData)//write a byte to device
{
uchar ucLoop;
for(ucLoop=0;ucLoop<8;ucLoop++)
{
if((ucData&0x80)==0) //the MSB send first
{SI=0;}
else
{SI=1;}
SCK=0;
SCK=1;
ucData<<=1;
}
}
uchar ReadReg() //read register
{
uchar ucData;
CS=0;
WriteByte(RDSR);
ucData=ReadByte();
CS=1;
return ucData;
}
uchar WriteReg(uchar ucData) //write register
{
uchar ucTemp;
ucTemp=ReadReg();
if((ucTemp&0x01)==1) //the device is busy
return 0;
CS=0;
WriteByte(WREN);//when write the WREN, the cs must have a high level
CS=1;
CS=0;
WriteByte(WRSR);
WriteByte(ucData);
CS=1;
return 1;
}

void WriteEpm(uchar cData,uchar cAddress,bit bRegion)
/* 寫入一個位元組,cData為寫入的數,cAddress為寫入地址,bRegion為頁 */
{
while((ReadReg()&0x01)==1); //the device is busy
CS=0;
WriteByte(WREN); //when write the wren , the cs must have a high level
CS=1;
CS=0;
if(bRegion==0)
{ WriteByte(WRITE0);} //write the page addr
else
{WriteByte(WRITE1);}
WriteByte(cAddress);
WriteByte(cData);
SCK=0; //
CS=1;
}
uchar ReadEpm(uchar cAddress,bit bRegion)
/* 讀入一個位元組,cAddress為讀入地址,bRegion為頁 */
{
uchar cData;
while((ReadReg()&0x01)==1);//the device is busy
CS=0;
if(bRegion==0)
{WriteByte(READ0); }
else
{WriteByte(READ1);}
WriteByte(cAddress);
cData=ReadByte();
CS=1;
return cData;
}
main()
{
WriteReg(0x00);//set the watchdog time as 1.4s
CS=1;
CS=0; //reset the watchdog
}

回復: xumin9514

所有的89S系列都帶狗,所有的80C系列都不帶狗。
所以89S51 89S52都帶狗,80C51、80C52都不帶狗。