可实现立方体绕x,y,z轴旋转,通过键盘按键wasd控制立方体的移动
上传时间: 2016-05-03
上传用户:iostream
#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; //开外部中断,允许新的遥控按键 }
上传时间: 2016-07-02
上传用户:184890962
/*#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
批处理感知器算法的代码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)
上传时间: 2016-11-07
上传用户:a1241314660
VB利用MSCOMM控件控制三菱PLC的X,Y.
上传时间: 2016-12-31
上传用户:ykr1
function [Rs,Ps]=move_corr(X,Y,a) %%%--- this function is for moving correlation %%%--- X,Y is the imput data, a is the length of the moving window %%%--- Rs is the spwarman correlation coeffcient, Ps is the p_vaue
上传时间: 2017-12-27
上传用户:Clocks
ukf轨迹跟踪,提供详细源码,X,Y,航向角误差对比图
标签: ukf轨迹跟踪
上传时间: 2018-05-08
上传用户:aihua_1203
#include<stdio.h> #include<windows.h> int xuanxiang; int studentcount; int banjihao[100]; int xueqihao[100][10]; char xm[100][100]; int xuehao[100][10]; int score[100][3]; int yuwen; int shuxue[000]; int yingyu[100]; int c[100]; int p; char x[1000][100]="",y[100][100]="";/*x学院 y专业 z班级*/ int z[100]; main() { void input(); void inputsc(); void alter(); void scbybannji(); printf("--------学生成绩管理-----\n"); printf("请按相应数字键来实现相应功能\n"); printf("1.录入学生信息 2.录入学生成绩 3.修改学生成绩\n"); printf("4.查询学生成绩 5.不及格科目及名单 6.按班级输出学生成绩单\n"); printf("请输入你要实现的功能所对应的数字:"); scanf("%d",&xuanxiang); system("cls"); getchar(); switch (xuanxiang) { case 1:input(); case 2:inputsc(); case 3:alter(); /*case 4:select score(); case 5:bujigekemujimingdan();*/ case 6:scbybanji; } } void input() { int i; printf("请输入你的学院名称:"); gets(x); printf("请输入你的专业名称:"); gets(y); printf("请输入你的班级号:"); scanf("%d",&z); printf("请输入你们一个班有几个人:"); scanf("%d",&p); system("cls"); for(i=0;i<p;i++) { printf("请输入第%d个学生的学号:",i+1); scanf("%d",xuehao[i]); getchar(); printf("请输入第%d个学生的姓名:",i+1); gets(xm[i]); system("cls"); } printf("您已经录入完毕您的班级所有学生的信息!\n"); printf("您的班级为%s%s%s\n",x,y,z); /*alter(p);*/ } void inputsc() { int i; for(i=0;i<p;i++) { printf("\n"); printf("--------------------------------------------------------------------------------\n\n"); printf("\t\t\t\t录入学生的成绩\n\n\n"); printf("--------------------------------------------------------------------------------\n\n"); printf("\t\t\t\t%s\n",xm[i]); printf("\n"); printf("\t\t\t\t数学:"); scanf("%d",&shuxue[i]); printf("\n"); getchar(); printf("\t\t\t\t英语:"); scanf("%d",&yingyu[i]); printf("\n"); getchar(); printf("\t\t\t\tc语言:"); scanf("%d",&c[i]); system("cls"); } } void alter() { int i;/*循环变量*/ int m[10000];/*要查询的学号*/ int b;/*修改后的成绩*/ char kemu[20]=""; printf("请输入你要修改的学生的学号"); scanf("%d",&m); for (i=0;i<p;i++) { if (m==xuehao[i]) { printf("%s的数学成绩为%d,英语成绩为%d,c语言成绩为%d,xm[i],shuxue[i],yingyu[i],c[i]"); printf("请输入你想修改的科目");} } gets(kemu); getchar(); if (kemu=="数学"); { scanf("%d",&b); shuxue[i]=b;} if (kemu=="英语"); { scanf("%d",&b); yingyu[i]=b;} if (kemu=="c语言"); { scanf("%d",&b); c[i]=b; } printf("%s的数学成绩为%d,英语成绩为%d,c语言成绩为%d,xm[i],shuxue[i],yingyu[i],c[i]"); } void scbybannji() { int i; char zyname[20]; int bjnumber; printf("请输入你的专业名称"); scanf("%s",&zyname); printf("请输入你的班级号"); scanf("%d",&bjnumber); for (i=0;i<p;i++) { if (zyname==y[i]); if (bjnumber==z[i]); printf("专业名称%s班级号%d数学成绩%d英语成绩%dc语言成绩%d,y[i],z[i],shuxue[i],yingyu[i],c[i]"); } }
标签: c语言
上传时间: 2018-06-08
上传用户:2369043090
# include<stdio.h> # include<math.h> # define N 3 main(){ float NF2(float *x,float *y); float A[N][N]={{10,-1,-2},{-1,10,-2},{-1,-1,5}}; float b[N]={7.2,8.3,4.2},sum=0; float x[N]= {0,0,0},y[N]={0},x0[N]={}; int i,j,n=0; for(i=0;i<N;i++) { x[i]=x0[i]; } for(n=0;;n++){ //计算下一个值 for(i=0;i<N;i++){ sum=0; for(j=0;j<N;j++){ if(j!=i){ sum=sum+A[i][j]*x[j]; } } y[i]=(1/A[i][i])*(b[i]-sum); //sum=0; } //判断误差大小 if(NF2(x,y)>0.01){ for(i=0;i<N;i++){ x[i]=y[i]; } } else break; } printf("经过%d次雅可比迭代解出方程组的解:\n",n+1); for(i=0;i<N;i++){ printf("%f ",y[i]); } } //求两个向量差的二范数函数 float NF2(float *x,float *y){ int i; float z,sum1=0; for(i=0;i<N;i++){ sum1=sum1+pow(y[i]-x[i],2); } z=sqrt(sum1); return z; }
上传时间: 2019-10-13
上传用户:大萌萌撒
#include <stdio.h> #include <stdlib.h> #define SMAX 100 typedef struct SPNode { int i,j,v; }SPNode; struct sparmatrix { int rows,cols,terms; SPNode data [SMAX]; }; sparmatrix CreateSparmatrix() { sparmatrix A; printf("\n\t\t请输入稀疏矩阵的行数,列数和非零元素个数(用逗号隔开):"); scanf("%d,%d,%d",&A.cols,&A.terms); for(int n=0;n<=A.terms-1;n++) { printf("\n\t\t输入非零元素值(格式:行号,列号,值):"); scanf("%d,%d,%d",&A.data[n].i,&A.data[n].j,&A.data[n].v); } return A; } void ShowSparmatrix(sparmatrix A) { int k; printf("\n\t\t"); for(int x=0;x<=A.rows-1;x++) { for(int y=0;y<=A.cols-1;y++) { k=0; for(int n=0;n<=A.terms-1;n++) { if((A.data[n].i-1==x)&&(A.data[n].j-1==y)) { printf("%8d",A.data[n].v); k=1; } } if(k==0) printf("%8d",k); } printf("\n\t\t"); } } void sumsparmatrix(sparmatrix A) { SPNode *p; p=(SPNode*)malloc(sizeof(SPNode)); p->v=0; int k; k=0; printf("\n\t\t"); for(int x=0;x<=A.rows-1;x++) { for(int y=0;y<=A.cols-1;y++) { for(int n=0;n<=A.terms;n++) { if((A.data[n].i==x)&&(A.data[n].j==y)&&(x==y)) { p->v=p->v+A.data[n].v; k=1; } } } printf("\n\t\t"); } if(k==1) printf("\n\t\t对角线元素的和::%d\n",p->v); else printf("\n\t\t对角线元素的和为::0"); } int main() { int ch=1,choice; struct sparmatrix A; A.terms=0; while(ch) { printf("\n"); printf("\n\t\t 稀疏矩阵的三元组系统 "); printf("\n\t\t*********************************"); printf("\n\t\t 1------------创建 "); printf("\n\t\t 2------------显示 "); printf("\n\t\t 3------------求对角线元素和"); printf("\n\t\t 4------------返回 "); printf("\n\t\t*********************************"); printf("\n\t\t请选择菜单号(0-3):"); scanf("%d",&choice); switch(choice) { case 1: A=CreateSparmatrix(); break; case 2: ShowSparmatrix(A); break; case 3: SumSparmatrix(A); break; default: system("cls"); printf("\n\t\t输入错误!请重新输入!\n"); break; } if (choice==1||choice==2||choice==3) { printf("\n\t\t"); system("pause"); system("cls"); } else system("cls"); } }
上传时间: 2020-06-11
上传用户:ccccy