虫虫首页| 资源下载| 资源专辑| 精品软件
登录| 注册

WHILE

WHILE是计算机的一种基本循环模式。当满足条件时进入循环,进入循环后,当条件不满足时,跳出循环。WHILE语句的一般表达式为:WHILE(表达式){循环体}。
  • 红外遥控RGB

    #include "STC90.h" #include < intrins.h > #define uchar unsigned char #define uint unsigned int #define led_port P1 sbit IR_RE = P3^2; sbit led_r = P1^3; sbit led_g = P1^4; sbit led_b = P1^5; sbit led_wd = P1^7; sbit K1 =P3^0 ; //增加键 sbit K2 =P3^1 ; //减少键 sbit BEEP =P3^7 ; //蜂鸣器 uchar temp,temp1; bit k=0; //红外解码判断标志位,为0则为有效信号,为1则为无效 bit Flag2; uchar date[4]={0,0,0,0}; //date数组为存放地址原码,反码,数据原码,反码 uint lade_1,lade_2,lade_3,lade_4; uint num; uchar date_ram,ee_temp,ee_temp1; uchar WDT_NUM=0; uchar const dofly[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// 显示段码值01234567 uchar code seg[]={7,6,5,4,3,2,1,0};//分别对应相应的数码管点亮,即位码 unsigned long disp_date; void fade(); void fade1(); /*************************** 看门狗子程序*************************/ void watchdog_timer() { if(WDT_NUM==5) { WDT_NUM=0; led_wd=!led_wd; } WDT_NUM++; WDT_CONTR=0x3f; } /******************************************************************/ void delay(unsigned int cnt) { WHILE(--cnt); } /*--------------------------延时1ms程子程序-----------------------*/ void delay_1ms(uint z) { uint x,y; for(x=z;x>0;x--) for(y=126;y>0;y--); } /*--------------------------延时1ms程子程序-----------------------*/ delay1000() { uchar i,j; i=5; do{j=95; do{j--;} WHILE(j); i--; } WHILE(i); } /*---------------------------延时882us子程序-----------------------*/ delay882() { uchar i,j; i=6; do{j=71; do{j--;} WHILE(j); i--; }WHILE(i); } /*--------------------------延时2400us程子程序-----------------------*/ delay2400() { uchar i,j; i=5; do{j=237; do{j--;} WHILE(j); i--; }WHILE(i); } /**********************************************************************/ /* void display() { uchar i; for(i=0;i<8;i++) { P0=dofly[disp_date%10];//取显示数据,段码 P2=seg[i]; //取位码 delay_1ms(1); disp_date/=10; } } */ /*********************************************************************/ uchar EEPROM_read(uint addr)//EEPROM字节读 { ISP_CONTR=0x83; //系统时钟<12M时,对ISP_CONTR寄存器设置的值,本电路为11.0592M ISP_CMD=1; //字节读 ISP_ADDRH=(addr&0xff00)>>8; ISP_ADDRL=addr&0x00ff; ISP_TRIG=0x46; ISP_TRIG=0xb9; _nop_(); _nop_(); return ISP_DATA; } //-------------------------------------------------------------------- void EEPROM_write(uint addr,uchar dat)//EEPROM字节写 { ISP_CONTR=0x83; //系统时钟<12M时,对ISP_CONTR寄存器设置的值,本电路为11.0592M ISP_CMD=2; //字节编程 ISP_ADDRH=(addr&0xff00)>>8; ISP_ADDRL=addr&0x00ff; ISP_DATA=dat; ISP_TRIG=0x46; ISP_TRIG=0xb9; _nop_(); _nop_(); } //-------------------------------------------------------------------- void EEPROM_ERASE(uint addr)//EEPROM扇区擦除 { ISP_CONTR=0x83; //系统时钟<12M时,对ISP_CONTR寄存器设置的值,本电路为11.0592M ISP_CMD=3; //扇区擦除 ISP_ADDRH=(addr&0xff00)>>8; ISP_ADDRL=addr&0x00ff; ISP_TRIG=0x46; ISP_TRIG=0xb9; _nop_(); _nop_(); } //************************************************************** /*----------------------------------------------------------*/ /*-----------------------红外解码程序(核心)-----------------*/ /*----------------------------------------------------------*/ void IR_decode() { uchar i,j; WHILE(IR_RE==0); delay2400(); if(IR_RE==1) //延时2.4ms后如果是高电平则是新码 { delay1000(); delay1000(); for(i=0;i<4;i++) { for(j=0;j<8;j++) { WHILE(IR_RE==0); //等待地址码第1位高电平到来 delay882(); //延时882us判断此时引脚电平 ///CY=IR_RE; if(IR_RE==0) { date[i]>>=1; date[i]=date[i]|0x00; } else if(IR_RE==1) { delay1000(); date[i]>>=1; date[i]=date[i]|0x80; } } //1位数据接收结束 } //32位二进制码接收结束 } } /* void LED_PWM() { lade_2=num; //384 lade_4=num; //384 WHILE(lade_2!=0&Flag2==1) { for(lade_3=512;lade_3>lade_4;lade_3--) //512 { led_port=0x00; delay(1); } lade_3=512; //512 lade_4--; for(lade_1=0;lade_1<lade_2;lade_1++) { led_port=0x38; //c7 delay(1); } lade_1=0; lade_2--; if(temp!=0x0c&Flag2==1) { lade_2=0; } lade_2=num; //384 lade_4=num; //384 } } */ void calc() { EEPROM_read(0x2000); ee_temp1=ISP_DATA; ee_temp=ee_temp1&0x0f; //************************************* 1 /* if(date[3]==0xff&Flag2==1) { if(num>=20) { num=num-80; } //else num=1; LED_PWM(); } if(date[3]==0xfe&Flag2==1) { if(num<=500) { num=num+80; } // else num=511; LED_PWM(); } if(ee_temp1==0xfd) { led_port=0x00; watchdog_timer(); } if(ee_temp1==0xfc) { led_port=0x00; led_r=1; led_g=1; led_b=1; watchdog_timer(); } */ //********************************************** 2 if(ee_temp1==0xfb) { led_port=0x00; led_r=1; watchdog_timer(); } if(ee_temp1==0xfa) { led_port=0x00; led_g=1; watchdog_timer(); } if(ee_temp1==0xf9) { led_port=0x00; led_b=1; watchdog_timer(); } if(ee_temp1==0xf8) { led_port=0x00; led_r=1; led_g=1; led_b=1; watchdog_timer(); } //************************************** 3 if(ee_temp1==0xf7) { uint fade_1,fade_2,fade_3,fade_4; fade_2=448; //384 fade_4=448; //384 WHILE(fade_2!=0&ee_temp==0x07) { for(fade_3=512;fade_3>fade_4;fade_3--) //512 { led_port=0x10; delay(1); } fade_3=512; //512 fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x08; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x07) { fade_2=0; } watchdog_timer(); fade_2=448; //384 fade_4=448; //384 } } if(ee_temp1==0xf6) { uint fade_1,fade_2,fade_3,fade_4; fade_2=448; //384 fade_4=448; //384 WHILE(fade_2!=0&ee_temp==0x06) { for(fade_3=512;fade_3>fade_4;fade_3--) //512 { led_port=0x20; delay(1); } fade_3=512; //512 fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x10; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x06) { fade_2=0; } watchdog_timer(); fade_2=448; //384 fade_4=448; //384 } } if(ee_temp1==0xf5) { uint fade_1,fade_2,fade_3,fade_4; fade_2=448; //384 fade_4=448; //384 WHILE(fade_2!=0&ee_temp==0x05) { for(fade_3=512;fade_3>fade_4;fade_3--) //512 { led_port=0x08; delay(1); } fade_3=512; //512 fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x20; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x05) { fade_2=0; } watchdog_timer(); fade_2=448; //384 fade_4=448; //384 } } if(ee_temp1==0xf4) { WHILE(ee_temp==4) { led_port=0x00; led_r=1; delay_1ms(200); led_port=0x00; led_r=1; led_g=1; delay_1ms(200); led_port=0x00; led_g=1; delay_1ms(200); watchdog_timer(); led_port=0x00; led_g=1; led_b=1; delay_1ms(200); led_port=0x00; led_b=1; delay_1ms(200); led_port=0x00; led_b=1; led_r=1; delay_1ms(200); watchdog_timer(); } } //************************************** 4 if(ee_temp1==0xf3) { uint fade_1,fade_2,fade_3,fade_4; fade_2=416; //384 fade_4=416; //384 WHILE(fade_2!=0&ee_temp==0x03) { for(fade_3=512;fade_3>fade_4;fade_3--) //512 { led_port=0x10; delay(1); } fade_3=512; //512 fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x08; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x03) { fade_2=0; } watchdog_timer(); fade_2=416; //384 fade_4=416; //384 } } if(ee_temp1==0xf2) { uint fade_1,fade_2,fade_3,fade_4; fade_2=384; //384 fade_4=384; //384 WHILE(fade_2!=0&ee_temp==0x02) { for(fade_3=512;fade_3>fade_4;fade_3--) //512 { led_port=0x20; delay(1); } fade_3=512; //512 fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x10; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x02) { fade_2=0; } watchdog_timer(); fade_2=384; //384 fade_4=384; //384 } } if(ee_temp1==0xf1) { uint fade_1,fade_2,fade_3,fade_4; fade_2=348; //384 fade_4=348; //384 WHILE(fade_2!=0&ee_temp==0x01) { for(fade_3=512;fade_3>fade_4;fade_3--) //512 { led_port=0x08; delay(1); } fade_3=512; //512 fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x20; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x01) { fade_2=0; } watchdog_timer(); fade_2=348; //384 fade_4=348; //384 } } if(ee_temp1==0xf0) { WHILE(ee_temp==0) { led_port=0x00; led_r=1; delay_1ms(500); watchdog_timer(); led_port=0x00; led_g=1; delay_1ms(500); led_port=0x00; led_b=1; delay_1ms(500); watchdog_timer(); } } //******************************************** 5 if(ee_temp1==0xef) { uint fade_1,fade_2,fade_3,fade_4; fade_2=384; //384 fade_4=384; //384 WHILE(fade_2!=0&ee_temp==0x0f) { for(fade_3=512;fade_3>fade_4;fade_3--) //512 { led_port=0x10; delay(1); } fade_3=512; //512 fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x08; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x0f) { fade_2=0; } watchdog_timer(); fade_2=384; //384 fade_4=384; //384 } } if(ee_temp1==0xee) { uint fade_1,fade_2,fade_3,fade_4; fade_2=320; //384 fade_4=320; //384 WHILE(fade_2!=0&ee_temp==0x0e) { for(fade_3=512;fade_3>fade_4;fade_3--) //512 { led_port=0x20; delay(1); } fade_3=512; //512 fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x10; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x0e) { fade_2=0; } watchdog_timer(); fade_2=320; //384 fade_4=320; //384 } } if(ee_temp1==0xed) { uint fade_1,fade_2,fade_3,fade_4; fade_2=320; //384 fade_4=320; //384 WHILE(fade_2!=0&ee_temp==0x0d) { for(fade_3=512;fade_3>fade_4;fade_3--) //512 { led_port=0x08; delay(1); } fade_3=512; //512 fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x20; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x0d) { fade_2=0; } watchdog_timer(); fade_2=320; //384 fade_4=320; //384 } } if(ee_temp1==0xec) fade(); //******************************************* 6 if(ee_temp1==0xeb) { led_port=0x00; led_r=1; led_g=1; watchdog_timer(); } if(ee_temp1==0xea) { led_port=0x00; //led_r=0; led_g=1; led_b=1; watchdog_timer(); } if(ee_temp1==0xe9) { led_port=0x00; led_r=1; //led_g=0; led_b=1; watchdog_timer(); } if(ee_temp1==0xe8) fade1(); } void fade() { // uchar i; uint fade_1,fade_2,fade_3,fade_4; fade_2=512; fade_4=511; WHILE(fade_2!=0&ee_temp==0x0c) { for(fade_3=512;fade_3>fade_4;fade_3--) { led_port=0x10; delay(1); } fade_3=512; fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x08; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x0c) { fade_2=0; } } watchdog_timer(); fade_2=512; fade_4=511; WHILE(fade_2!=0&ee_temp==0x0c) { if(ee_temp!=0x0c) { fade_2=0; } for(fade_3=512;fade_3>fade_4;fade_3--) { led_port=0x20; delay(1); // watchdog_timer(); } fade_3=512; fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x10; delay(1); // watchdog_timer(); } fade_1=0; fade_2--; } watchdog_timer(); fade_2=512; fade_4=511; WHILE(fade_2!=0&ee_temp==0x0c) { if(ee_temp!=0x0c) { fade_2=0; } for(fade_3=512;fade_3>fade_4;fade_3--) { led_port=0x08; delay(1); watchdog_timer(); } fade_3=512; fade_4--; watchdog_timer(); for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x20; delay(1); watchdog_timer(); } fade_1=0; fade_2--; } watchdog_timer(); } void fade1() { // uchar i; uint fade_1,fade_2,fade_3,fade_4; fade_2=128; fade_4=127; WHILE(fade_2!=0&ee_temp==0x08) { for(fade_3=128;fade_3>fade_4;fade_3--) { led_port=0x10; delay(1); } fade_3=128; fade_4--; for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x08; delay(1); } fade_1=0; fade_2--; if(ee_temp!=0x08) { fade_2=0; } } watchdog_timer(); fade_2=128; fade_4=127; WHILE(fade_2!=0&ee_temp==0x08) { if(ee_temp!=0x08) { fade_2=0; } for(fade_3=128;fade_3>fade_4;fade_3--) { led_port=0x20; delay(1); } fade_3=128; fade_4--; for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x10; delay(1); } fade_1=0; fade_2--; } watchdog_timer(); fade_2=128; fade_4=127; WHILE(fade_2!=0&ee_temp==0x08) { if(ee_temp!=0x08) { fade_2=0; } for(fade_3=128;fade_3>fade_4;fade_3--) { led_port=0x08; delay(1); } fade_3=128; fade_4--; for(fade_1=0;fade_1<fade_2;fade_1++) { led_port=0x20; delay(1); } fade_1=0; fade_2--; } watchdog_timer(); } void init() { led_port=0x00; /* led_r=1; delay_1ms(500); led_port=0x00; led_g=1; delay_1ms(500); led_port=0x00; led_b=1; delay_1ms(500); led_port=0x00; */ delay_1ms(2); WDT_CONTR=0x3f; delay_1ms(500); } //******************************** void main() { init(); Flag2=0; SP=0x60; //堆栈指针 EX0=1; //允许外部中断0,用于检测红外遥控器按键 EA=1; num=255; WHILE(1) { calc(); } } //******************************************************************** /*------------------------外部中断0程序-------------------------*/ /*------------------主要用于处理红外遥控键值--------------------*/ void int0() interrupt 0 { uchar i; Flag2=0; /////// k=0; EX0=0; //检测到有效信号关中断,防止干扰 for(i=0;i<4;i++) { delay1000(); if(IR_RE==1){k=1;} //刚开始为9ms的引导码. } led_port=0x00; if(k==0) { IR_decode(); //如果接收到的是有效信号,则调用解码程序 if(date[3]>=0xe8) { if(date[3]<=0xfb) { temp1=date[3]; EEPROM_ERASE(0x2000); //STC_EEROM_0X2000 temp1 EEPROM_write(0x2000,temp1); EEPROM_read(0x2000); ee_temp1=ISP_DATA; ee_temp=ee_temp1&0x0f; /* temp=date[3]&0x0f; EEPROM_ERASE(0x2004); //STC_EEROM_0X2004 temp EEPROM_write(0x2004,temp); */ } else { EEPROM_read(0x2000); ee_temp1=ISP_DATA; ee_temp=ee_temp1&0x0f; } } delay2400(); delay2400(); delay2400(); delay_1ms(500); } EX0=1; //开外部中断,允许新的遥控按键 }

    标签: RGB 红外遥控

    上传时间: 2016-07-02

    上传用户:184890962

  • 调光C程序

    /*#include<reg52.h> #define uint unsigned int #define uchar unsigned char #define uchar unsigned char sbit K1=P3^4; sbit K2=P3^5; sbit ledr=P1^0; sbit ledg=P1^1; sbit ledb=P1^2; bit LEDDirection=0;//LED控制方向0:渐亮1:渐灭 char  pwm=0; char  pwmr=0; char  scw=0;//中断记数 char  tt=0; char n; void dealy(uint z); void Timer0Init(void) {    TMOD=0x01;   TH0=0xff;   TL0=0x47;   EX0=1;    IT0=0;   PX0=1;   ET0=1;    TR0=1;   EA=1; } void main() {   Timer0Init();       WHILE(1){ if(K1==0) { dealy (1); if(K1==0) {TR0=1;   ledr=0;       dealy(5);       TR0=0;       }          }      if(K2==0) { dealy (1); if(K2==0) { WHILE(1) {     ledr=0;  //亮     dealy(100-n*10);     ledr=1;  //熄     dealy(n*10); }   }  }       } } void Time0Isr(void) interrupt 1 {        // pwm=0;      TH0=0xff;      TL0=0x47;          scw++; }*/ #include<reg52.h> #define uchar unsigned char bit LEDDirection=0; sbit P2_0=P1^0; sbit key1=P3^4; sbit key2=P3^5; sbit key3=P3^6; uchar zkb,i,t;// zkb指占空比 uchar pwm; void delay(uchar z) {   uchar x,y;   for(x=z;x>0;x--)    for(y=110;y>0;y--); } void init()  //初始化函数 {      TMOD=0X01;   TH0=(65536-1000)/256;   TL0=(65536-1000)%256;   EA=1;   ET0=1;   TR0=1; } void keyscan()  //键盘扫描   {     P3=0XFF; if(key1==0)   {    delay(5);     if(key1==0)     {      WHILE(!key1);         if(zkb<9)    {      zkb++;    }        }   } if(key2==0)   {    delay(5);     if(key2==0)     {      WHILE(!key2);      if(zkb>0)      {      zkb--;    }     }    }    if(key3==0)   {TR0=1;    delay(5);     if(key3==0)     {WHILE(!key3);    if((zkb<=9)&&(0==LEDDirection))       {            zkb++;                 if(zkb>9)        {           LEDDirection=1;          zkb=9;                   }                }                   if((zkb>=0 )&&(1==LEDDirection))          {         zkb--;                   if(zkb<0 )       {          LEDDirection=0;         zkb=0 ;              //dealy(3000);       }                       }                 }    //pwm=pwmr;                              }             } void main() //主函数   {          zkb=2;     init(); WHILE(1) {   keyscan(); }   } void time0(void) interrupt 1  //中断函数   {          TH0=(65536-200)/256; TL0=(65536-200)%256; ++i;   if(i>10)    {    i=0;    }; if(i<=zkb) {   P2_0=1; } else P2_0=0;   } /*void time0(void) interrupt 0  //中断函数   {          TH0=(65536-1000)/256; TL0=(65536-1000)%256; ++i; if(i>10)    {    i=0;    }; if(i<=zkb) {   P2_0=1; } else P2_0=0;   }*/

    标签: 调光

    上传时间: 2016-07-02

    上传用户:184890962

  • 基于8051+Proteus仿真案例

    基础程序设计 01 闪烁的LED  /*  名称闪烁的LED   说明LED按设定的时间间隔闪烁 */  #include<reg51.h>  #define uchar unsigned char  #define uint unsigned int  sbit LED=P1^0;  //延时  void DelayMS(uint x)  {   uchar i;   WHILE(x--) {    for(i=0;i<120;i++);   }  }  //主程序  void main() {   WHILE(1) {    LED=~LED;    DelayMS(150);   }  } 

    标签: 基于8051仿真 基于Proteus仿真 基于8051+Proteus仿真

    上传时间: 2016-09-19

    上传用户:xinhoujue

  • 51单片机C语言程序设计Proteus仿真实训

    基础程序设计 01 闪烁的LED  /*  名称闪烁的LED   说明LED按设定的时间间隔闪烁  */  #include<reg51.h>  #define uchar unsigned char  #define uint unsigned int  sbit LED=P1^0;  //延时  void DelayMS(uint x) {   uchar i;   WHILE(x--) {    for(i=0;i<120;i++);   } }  //主程序  void main() {   WHILE(1)  {    LED=~LED;    DelayMS(150);   }  } 

    标签: 51单片机C语言程序设计 51单片机C语言程序设计Proteus仿真实训

    上传时间: 2016-09-19

    上传用户:xinhoujue

  • 批处理感知器算法

    批处理感知器算法的代码matlab w1=[1,0.1,1.1;1,6.8,7.1;1,-3.5,-4.1;1,2.0,2.7;1,4.1,2.8;1,3.1,5.0;1,-0.8,-1.3;     1,0.9,1.2;1,5.0,6.4;1,3.9,4.0]; w2=[1,7.1,4.2;1,-1.4,-4.3;1,4.5,0.0;1,6.3,1.6;1,4.2,1.9;1,1.4,-3.2;1,2.4,-4.0;     1,2.5,-6.1;1,8.4,3.7;1,4.1,-2.2]; w3=[1,-3.0,-2.9;1,0.5,8.7;1,2.9,2.1;1,-0.1,5.2;1,-4.0,2.2;1,-1.3,3.7;1,-3.4,6.2;     1,-4.1,3.4;1,-5.1,1.6;1,1.9,5.1]; figure; plot(w3(:,2),w3(:,3),'ro'); hold on; plot(w2(:,2),w2(:,3),'b+'); W=[w2;-w3];%增广样本规范化 a=[0,0,0]; k=0;%记录步数 n=1; y=zeros(size(W,2),1);%记录错分的样本 WHILE any(y<=0)     k=k+1;     y=a*transpose(W);%记录错分的样本     a=a+sum(W(find(y<=0),:));%更新a     if k >= 250         break     end end if k<250     disp(['a为:',num2str(a)])      disp(['k为:',num2str(k)]) else      disp(['在250步以内没有收敛,终止']) end %判决面:x2=-a2*x1/a3-a1/a3 xmin=min(min(w1(:,2)),min(w2(:,2))); xmax=max(max(w1(:,2)),max(w2(:,2))); x=xmin-1:xmax+1;%(xmax-xmin): y=-a(2)*x/a(3)-a(1)/a(3); plot(x,y)

    标签: 批处理 算法matlab

    上传时间: 2016-11-07

    上传用户:a1241314660

  • 利用栈的基本操作实现将任意一个十进制整数N转化为R进制整数。

    #include <stdlib.h> #include<stdio.h> #include <malloc.h> #define stack_init_size 100 #define stackincrement 10 typedef struct sqstack { int *base; int *top; int stacksize; } sqstack; int StackInit(sqstack *s) { s->base=(int *)malloc(stack_init_size *sizeof(int)); if(!s->base) return 0; s->top=s->base; s->stacksize=stack_init_size; return 1; } int Push(sqstack *s,int e) { if(s->top-s->base>=s->stacksize) { s->base=(int *)realloc(s->base,(s->stacksize+stackincrement)*sizeof(int)); if(!s->base) return 0; s->top=s->base+s->stacksize; s->stacksize+=stackincrement; } *(s->top++)=e; return e; } int Pop(sqstack *s,int e) { if(s->top==s->base) return 0; e=*--s->top; return e; } int stackempty(sqstack *s) { if(s->top==s->base) { return 1; } else { return 0; } } int conversion(sqstack *s) { int n,e=0,flag=0; printf("输入要转化的十进制数:\n"); scanf("%d",&n); printf("要转化为多少进制:\n"); scanf("%d",&flag); printf("将十进制数%d 转化为%d 进制是:\n",n,flag); WHILE(n) { Push(s,n%flag); n=n/flag; } WHILE(!stackempty(s)) { e=Pop(s,e); switch(e) { case 10: printf("A"); break; case 11: printf("B"); break; case 12: printf("C"); break; case 13: printf("D"); break; case 14: printf("E"); break; case 15: printf("F"); break; default: printf("%d",e); } } printf("\n"); return 0; } int main() { sqstack s; StackInit(&s); conversion(&s); return 0;                        }

    标签: 整数 基本操作 十进制 转化 进制

    上传时间: 2016-12-08

    上传用户:爱你198

  • 运动会源代码

    #include <malloc.h>       #include <stdio.h>       #include <stdlib.h>       #include <string.h>       #define NULL 0      #define MaxSize 30          typedef struct athletestruct /*运动员*/     {         char name[20];          int score; /*分数*/         int range; /**/         int item; /*项目*/     }ATH;     typedef struct schoolstruct /*学校*/     {         int count; /*编号*/         int serial; /**/          int menscore; /*男选手分数*/         int womenscore; /*女选手分数*/         int totalscore; /*总分*/         ATH athlete[MaxSize]; /**/         struct schoolstruct *next;      }SCH;         int nsc,msp,wsp;      int ntsp;      int i,j;      int overgame;      int serial,range;      int n;      SCH *head,*pfirst,*psecond;      int *phead=NULL,*pafirst=NULL,*pasecond=NULL;     void create();         void input ()     {         char answer;          head = (SCH *)malloc(sizeof(SCH)); /**/         head->next = NULL;         pfirst = head;          answer = 'y';         WHILE ( answer == 'y' )         {         Is_Game_DoMain:         printf("\nGET Top 5 when odd\nGET Top 3 when even");         printf("\n输入运动项目序号 (x<=%d):",ntsp);         scanf("%d",pafirst);         overgame = *pafirst;         if ( pafirst != phead )         {             for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ )             {                 if ( overgame == *pasecond )                 {                     printf("\n这个项目已经存在请选择其他的数字\n");                     goto Is_Game_DoMain;                 }             }         }         pafirst = pafirst + 1;         if ( overgame > ntsp )         {             printf("\n项目不存在");             printf("\n请重新输入");             goto Is_Game_DoMain;         }         switch ( overgame%2 )         {         case 0: n = 3;break;         case 1: n = 5;break;         }         for ( i = 1 ; i <= n ; i++ )         {         Is_Serial_DoMain:         printf("\n输入序号 of the NO.%d (0<x<=%d): ",i,nsc);                 scanf("%d",&serial);         if ( serial > nsc )          {             printf("\n超过学校数目,请重新输入");             goto Is_Serial_DoMain;         }         if ( head->next == NULL )          {             create();         }         psecond = head->next ;          WHILE ( psecond != NULL )          {             if ( psecond->serial == serial )             {                 pfirst = psecond;                 pfirst->count = pfirst->count + 1;                 goto Store_Data;             }             else             {                 psecond = psecond->next;             }         }         create();         Store_Data:                 pfirst->athlete[pfirst->count].item = overgame;         pfirst->athlete[pfirst->count].range = i;         pfirst->serial = serial;         printf("Input name:) : ");                 scanf("%s",pfirst->athlete[pfirst->count].name);         }         printf("\n继续输入运动项目(y&n)?");         answer = getchar();         printf("\n");         }     }         void calculate() /**/     {         pfirst = head->next;         WHILE ( pfirst->next != NULL )         {             for (i=1;i<=pfirst->count;i++)             {                 if ( pfirst->athlete[i].item % 2 == 0 )                  {                     switch (pfirst->athlete[i].range)                     {                     case 1:pfirst->athlete[i].score = 5;break;                     case 2:pfirst->athlete[i].score = 3;break;                     case 3:pfirst->athlete[i].score = 2;break;                     }                 }                 else                  {                     switch (pfirst->athlete[i].range)                     {                     case 1:pfirst->athlete[i].score = 7;break;                     case 2:pfirst->athlete[i].score = 5;break;                     case 3:pfirst->athlete[i].score = 3;break;                     case 4:pfirst->athlete[i].score = 2;break;                     case 5:pfirst->athlete[i].score = 1;break;                     }                 }                 if ( pfirst->athlete[i].item <=msp )                  {                     pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score;                 }                 else                  {                     pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score;                 }             }             pfirst->totalscore = pfirst->menscore + pfirst->womenscore;             pfirst = pfirst->next;         }     }         void output()     {         pfirst = head->next;         psecond = head->next;         WHILE ( pfirst->next != NULL )          {             // clrscr();              printf("\n第%d号学校的结果成绩:",pfirst->serial);             printf("\n\n项目的数目\t学校的名字\t分数");             for (i=1;i<=ntsp;i++)              {                 for (j=1;j<=pfirst->count;j++)                  {                     if ( pfirst->athlete[j].item == i )                     {                                                                         printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;                                             }                 }             }             printf("\n\n\n\t\t\t\t\t\t按任意建 进入下一页");             getchar();             pfirst = pfirst->next;         }     //  clrscr();          printf("\n运动会结果:\n\n学校编号\t男运动员成绩\t女运动员成绩\t总分");         pfirst = head->next;         WHILE ( pfirst->next != NULL )         {             printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore);             pfirst = pfirst->next;         }         printf("\n\n\n\t\t\t\t\t\t\t按任意建结束");         getchar();     }         void create()     {                 pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct));         pfirst->next = head->next ;         head->next = pfirst ;                 pfirst->count = 1;         pfirst->menscore = 0;         pfirst->womenscore = 0;         pfirst->totalscore = 0;     }     void Save()     {FILE *fp;     if((fp = fopen("school.dat","wb"))==NULL)     {printf("can't open school.dat\n");     fclose(fp);     return;     }     fwrite(pfirst,sizeof(SCH),10,fp);     fclose(fp);     printf("文件已经成功保存\n");     }         void main()     {         system("cls");         printf("\n\t\t\t 运动会分数统计\n");         printf("输入学校数目 (x>= 5):");         scanf("%d",&nsc);          printf("输入男选手的项目(x<=20):");         scanf("%d",&msp);          printf("输入女选手项目(<=20):");         scanf("%d",&wsp);          ntsp = msp + wsp;                  phead = (int *)calloc(ntsp,sizeof(int));         pafirst = phead;         pasecond = phead;         input();         calculate();          output();         Save();     }             

    标签: 源代码

    上传时间: 2016-12-28

    上传用户:150501

  • 学生成绩管理啊

    #include "string.h" #include "ctype.h" #include "stdio.h" search(char pd[]) {FILE *fp;  int time=0,i=0,j=0,add[80],k=0,m;  char *ch,  str[900];  m=strlen(pd);  if((fp=fopen("haha.txt","r"))==NULL)  {   printf("Cannot open this file\n");   exit(0);  } for(;!feof(fp);i++)  {  str[i]=fgetc(fp);   if(tolower(str[i])==tolower(pd[k]))    {k++;     if(k==m)     if(!isalpha(i-m)&&!isalpha((str[i++]=fgetc(fp))))     {      time++;      add[j]=i-m+1;      j++;      k=0;     }     else k=0;   }  }   if(time)  {   printf("The time is:%d\n",time);   printf("The adders is:\n");   for(i=0;i<j;i++)   printf("%5d",add[i]);   if(i%5==0)   printf("\n");   getch();   fclose(fp);   }   else   printf("Sorry!Cannot find the word(^_^)"); } main() { char pd[10],choose='y'; int flag=1;     WHILE(flag)    {printf("In put the word you want to seqarch:");     scanf("%s",pd);     search(strlwr(pd));     printf("\nWould you want to continue?(Y/N):");     getchar();     scanf("%c",&choose);     if((tolower(choose))=='n')     flag=0;     else flag=1;    }   printf("Thanks for your using!Bye-bye!\n");   getch(); }

    标签: 学生专用

    上传时间: 2016-12-29

    上传用户:767483511

  • c#简单计算器

    // 学生管理.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); struct person {   char name[10];   int ID;   int cj_yw;   int cj_sx;   struct person* next;   struct person* pro; }per; int APIENTRY WinMain(HINSTANCE hInstance,                      HINSTANCE hPrevInstance,                      LPSTR     lpCmdLine,                      int       nCmdShow) {   // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow))  { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MY); // Main message loop: WHILE (GetMessage(&msg, NULL, 0, 0))  { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))  { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // //  FUNCTION: MyRegisterClass() // //  PURPOSE: Registers the window class. // //  COMMENTS: // //    This function and its usage is only necessary if you want this code //    to be compatible with Win32 systems prior to the 'RegisterClassEx' //    function that was added to Windows 95. It is important to call this function //    so that the application will get 'well formed' small icons associated //    with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX);  wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MY); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_MY; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // //   FUNCTION: InitInstance(HANDLE, int) // //   PURPOSE: Saves instance handle and creates main window // //   COMMENTS: // //        In this function, we save the instance handle in a global variable and //        create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {    HWND hWnd;    hInst = hInstance; // Store instance handle in our global variable    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);    if (!hWnd)    {       return FALSE;    }    ShowWindow(hWnd, nCmdShow);    UpdateWindow(hWnd);    return TRUE; } // //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // //  PURPOSE:  Processes messages for the main window. // //  WM_COMMAND - process the application menu //  WM_PAINT - Paint the main window //  WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message)  { case WM_COMMAND: wmId    = LOWORD(wParam);  wmEvent = HIWORD(wParam);  // Parse the menu selections: switch (wmId) { case IDM_ABOUT:   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);   break; case IDM_EXIT:   DestroyWindow(hWnd);   break; default:   return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam);    }    return 0; } // Mesage handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)  { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; }     return FALSE; }

    标签: 计算器 学生

    上传时间: 2016-12-29

    上传用户:767483511

  • 简单的计算器

    // 学生管理.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); struct person {   char name[10];   int ID;   int cj_yw;   int cj_sx;   struct person* next;   struct person* pro; }per; int APIENTRY WinMain(HINSTANCE hInstance,                      HINSTANCE hPrevInstance,                      LPSTR     lpCmdLine,                      int       nCmdShow) {   // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow))  { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MY); // Main message loop: WHILE (GetMessage(&msg, NULL, 0, 0))  { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))  { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // //  FUNCTION: MyRegisterClass() // //  PURPOSE: Registers the window class. // //  COMMENTS: // //    This function and its usage is only necessary if you want this code //    to be compatible with Win32 systems prior to the 'RegisterClassEx' //    function that was added to Windows 95. It is important to call this function //    so that the application will get 'well formed' small icons associated //    with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX);  wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MY); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_MY; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // //   FUNCTION: InitInstance(HANDLE, int) // //   PURPOSE: Saves instance handle and creates main window // //   COMMENTS: // //        In this function, we save the instance handle in a global variable and //        create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {    HWND hWnd;    hInst = hInstance; // Store instance handle in our global variable    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);    if (!hWnd)    {       return FALSE;    }    ShowWindow(hWnd, nCmdShow);    UpdateWindow(hWnd);    return TRUE; } // //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // //  PURPOSE:  Processes messages for the main window. // //  WM_COMMAND - process the application menu //  WM_PAINT - Paint the main window //  WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message)  { case WM_COMMAND: wmId    = LOWORD(wParam);  wmEvent = HIWORD(wParam);  // Parse the menu selections: switch (wmId) { case IDM_ABOUT:   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);   break; case IDM_EXIT:   DestroyWindow(hWnd);   break; default:   return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam);    }    return 0; } // Mesage handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)  { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; }     return FALSE; }

    标签: 学生 计算器

    上传时间: 2016-12-29

    上传用户:767483511