void main ( ) { int a,b; x = 1; y = 2; a = 3; b = 4; printStr("Results should be : a c e "); printLn(); if (3 == 3) { printStr("a "); } if (1 > 2) { printStr("b "); } else { printStr("c "); } if ((1 > 2) && (a < b)) { printStr("d "); } if ((1 > 2) || (a < b)) { printStr("e "); } printLn(); }
int main(int argc, const char * argv[]) { // Loop through over and over until user terminates program for (;;) { Vector a, b, c; // Get vector a printLn("Vector a"); a.askForValues(); printLn(""); // Get vector b printLn("Vector b"); b.askForValues(); printLn(""); // Print vectors printLn("Vector a = " + a.toString()); printLn("Vector b = " + b.toString()); // Cross vectors and print result c = a.crossWith(b); printLn("a x b = " + c.toString()); printLn(""); printLn("------------------------------------"); printLn(""); } return 0; }
void ConsoleRoboCupCtrl::executeFile(const std::string& name1, const std::string& name2, bool printError, RobotConsole* console, bool scenarioAndLocationOnly) { if(nesting == 10) printLn("Nesting Error"); else { ++nesting; bool print = false; for(std::string name : std::vector<std::string>({name1, name2})) { if(name == "") { print = printError; continue; } if((int)name.rfind('.') <= (int)name.find_last_of("\\/")) name = name + ".con"; if(name[0] != '/' && name[0] != '\\' && (name.size() < 2 || name[1] != ':')) name = std::string("Scenes\\") + name; InBinaryFile stream(name); if(!stream.exists()) { if(print) printLn(name + " not found"); print = printError; } else { std::string line; while(!stream.eof()) { line.resize(0); while(!stream.eof()) { char c[2] = " "; stream >> c[0]; if(c[0] == '\n') break; else if(c[0] != '\r') line = line + c; } if(line.find_first_not_of(" ") != std::string::npos) executeConsoleCommand(line, console, scenarioAndLocationOnly); } break; } } --nesting; } }
int main(void) { int array[] = {21, 25, 49, 25, 16,8}; int len = sizeof(array) / sizeof(*array); printLn(array, len); SelectionSort(array, len); printLn(array, len); return 0; }
void main ( ) { int c; printStr("Result should be: 8 10"); printLn(); c = a[0]; a[1] = 4; a[2] = 5; a[0] = foo( a[1] ); printInt(a[0]); printStr(" "); a[0] = foo( a[2] ); printInt(a[0]); printLn(); }
//print WITH new line and carriage return void printStringLn(char *data){ uint16_t i; uint16_t str_length = strlen(data); for(i = 0; i < str_length; i++) { uart_send_byte(data[i]); } printLn(); }
void printDec(int n){ int len=nCif(n); if (n<0){ len++; } if (len>(COL_COUNT-cursorX)){ printLn(); } printUl(n, cursorX*CHAR_WIDTH, cursorY*CHAR_HEIGHT); cursorX+=len; }
void ConsoleRoboCupCtrl::selectedObject(const SimRobot::Object& obj) { const QString& fullName = obj.getFullName(); std::string robotName = fullName.mid(fullName.lastIndexOf('.') + 1).toUtf8().constData(); for(Robot* robot : robots) if(robotName == robot->getName()) { selected.clear(); selected.push_back(robot->getRobotProcess()); printLn("robot " + robot->getName()); return; } }
/* Send/print unsigned or signed number over UART. Printable data for viewing on terminal. Call this function: printNumber(number, DEC); printNumber(2246, DEC); Base: DEC, HEX, OCT, BIN Data must be number, int32_t. */ void printNumberLn(int32_t number, uint8_t base){ if (number < 0) { printString("-"); number = -number; printUnsignedNumber(number, base); } else { printUnsignedNumber(number, base); } printLn(); }
void main ( ) { int x,z; z = 0; x = 2; printStr("Results should be : 10"); printLn(); z = z+(1+2); z = z+(3*4-5); printInt(z); printLn(); printStr("Results should be : 14"); printLn(); z = z+(x+0); z = z+(0+1*x); printInt(z); printLn(); }
int runVegas(void) { int i; double sd; double avgi; char mess[25]; FILE * iprt = NULL; int mode=1; void * pscr=NULL; static int n_Line=7; i=imkmom(inP1,inP2); if(veg_Ptr&&veg_Ptr->ndim!=i)clearGrid(); if(!veg_Ptr) veg_Ptr=vegas_init(i,50); if(nin_int == 2) strcpy(mess, "Cross section[pb]"); else strcpy(mess, " Width[Gev] "); /* ** save current session parameters */ w_sess__(NULL); /* ** open protocol and resulting files */ { char fname[50]; sprintf(fname,"%sprt_%d",outputDir,nSess); iprt=fopen(fname,"a"); if(ftell(iprt)==0) { fprintf(iprt," CalcHEP kinematics module \n The session parameters:\n"); w_sess__(iprt); fprintf(iprt,"===================================\n"); } } /* ** initkinematics */ while(correctHistList()) editHist(); /* *** Main cycle */ if(!integral.old || n_Line==7) { n_Line=7; scrcolor(Blue, BGmain); // printLn(iprt,&n_Line," #IT %20s Error %% nCall chi**2",mess); printLn(iprt,&n_Line," #IT %s Error[%%] nCalls Eff. chi^2",mess); } for(;;) { static int worn=1; char strmen[]="\030" " nSess = N2_1 " " nCalls = N1_1 " " Set Distributions " "*Start integration " " Display Distributions " " Clear statistic " " Freeze grid OFF " " Clear grid " " Event Cubes NCUBE " " Generate Events "; improveStr(strmen,"N1_1","%d",integral.ncall[0]); improveStr(strmen,"N2_1","%d",integral.itmx[0]); improveStr(strmen,"NCUBE","%d",EventGrid); if(integral.freeze) improveStr(strmen,"OFF","ON"); menu1(54,7,"",strmen,"n_veg_*",&pscr,&mode); switch(mode) { case 0: if(iprt) fclose(iprt); return 0; case 1: correctInt(50,12,"Enter new value ",&integral.itmx[0],1); break; case 2: correctLong(50,12,"Enter new value ",&integral.ncall[0],1); break; case 3: editHist(); break; case 4: if(veg_Ptr->fMax && !integral.freeze) { if(!mess_y_n(15,15,"You have event generator prepared.\n" " The answer 'Y' will start Vegas session \nwhich destroys it." " To save the event generator answer 'N' \nand set " " ' Freeze grid' ON")) break; else { free(veg_Ptr->fMax); veg_Ptr->fMax=NULL; veg_Ptr->nCubes=0;} } for (i = 1; i <= integral.itmx[0]; ++i) { double sum; char errtxt[100]=""; int k; if(integral.ncall[0]==0) break; nCall=0; negPoints=0; badPoints=0; hFill=1; if(vegas_int(veg_Ptr, integral.ncall[0],1.5*(!integral.freeze), func_, &avgi, &sd) ) break; integral.old=1; negPoints/=nCall; badPoints/=nCall; integral.nCallTot+=nCall; scrcolor(FGmain,BGmain); printLn(iprt,&n_Line,"%4d %12.4E %10.2E %8d %s", ++integral.n_it, avgi,avgi? 100*sd/(double)fabs(avgi):0.,nCall,effInfo()); if(negPoints<0) sprintf(errtxt+strlen(errtxt)," Negative points %.1G%%;", -100*negPoints/(avgi-2*negPoints)); if(badPoints) sprintf(errtxt+strlen(errtxt), "Bad Precision %.1G%%;",100*badPoints/(avgi-2*negPoints)); if(errtxt[0]) { scrcolor(Red,BGmain); printLn(iprt,&n_Line,"%s",errtxt); } integral.s0+=sd*sd; integral.s1+=avgi; integral.s2+=avgi*avgi; } integral.In=integral.s1/integral.n_it; integral.dI=sqrt(integral.s0)/integral.n_it; if(integral.n_it<=1 || integral.s0==0 ) integral.khi2=0; else integral.khi2=(integral.s2-integral.s1*integral.s1/integral.n_it)*integral.n_it/(integral.n_it-1)/fabs(integral.s0); scrcolor(FGmain,BGmain); printLn(iprt,&n_Line," < > %12.4E %10.2E %8d %7.7s %-7.1G" , integral.In, fabs(integral.In)? 100*integral.dI/(double)fabs(integral.In):0., integral.nCallTot, effInfo(), integral.khi2); if(histTab.strings) { char fname[20]; FILE * d; sprintf(fname,"distr_%d",nSess); d=fopen(fname,"w"); wrt_hist2(d,Process); fclose(d); } messanykey(54,11,"Integration is over"); /* integral.freeze=0; */ break; case 5: showHist(54,10,Process); break; case 6: clearStatistics(-1); messanykey(54,13,"Old results for integral\n" "and distributions\nare deleted."); break; case 7: integral.freeze=!integral.freeze; break; case 8: if(!integral.freeze || mess_y_n(15,15,"The information for Event Generator will be lost\n OK?")) { int ndim=veg_Ptr->ndim; vegas_finish(veg_Ptr); veg_Ptr=vegas_init(ndim,50); messanykey(57,11,"OK"); } break; case 9: if(correctLong(50,12,"Enter new value ",&EventGrid,1)) { if(veg_Ptr->fMax) {free(veg_Ptr->fMax); veg_Ptr->fMax=NULL;veg_Ptr->nCubes=0;}} break; case 10: if( !veg_Ptr || !veg_Ptr->fMax) { char * mess="Before event generation one has to launch Vegas session with freezed grid\n" "to prepare generator"; if(blind) { printf("%s\n",mess); sortie(200);} else messanykey(4,13,mess); } else runEvents(); } } }
int main(void) { int32_t result; int32_t av_result; uint8_t i = 0; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); systick_millis_init(); UART_Init(); //LEDS gpio_pinSetup(GPIOC, GPIO_Pin_8, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_Speed_40MHz); GPIO_ResetBits(GPIOC, GPIO_Pin_8); MAX11210_init(); printLn(); printStringLn("------------------------------------------------"); printStringLn("System initialized. Initialized jebote!"); MAX11210_set_meas_mode(MODE_SINGLE); for(i = 0; i < 5; i ++){ MAX11210_start_meas(MEASURE_10_SPS); MAX11210_read_result(); } MAX11210_calibration(); printString("\t SCOC:"); printNumberLn( MAX11210_read_reg(SCOC), DEC); printString( "\tSOC:"); printNumberLn(MAX11210_read_reg(SOC), DEC); printString("\t SCGC:"); printNumberLn(MAX11210_read_reg(SCGC), DEC); printString("\t SGC:"); printNumberLn(MAX11210_read_reg(SGC), DEC); while (1) { for(i = 0; i < AV_RATE; i++){ MAX11210_start_meas(MEASURE_10_SPS); result = MAX11210_read_result() & 0x00FFFFFF; if((result >> 23) == 0){ } else{ //negativna cifra result = result << 8; result = ~result + 1; result = result >> 8; result = -result; } av_result += result; result=0; } av_result = av_result / AV_RATE ; printNumberLn(av_result >> SHIFT, DEC); av_result = 0; //printString(USART1, "DATA: "); /* MAX11210_start_meas(MEASURE_10_SPS); result = MAX11210_read_result() & 0x00FFFFFF; if((result >> 23) == 0){ printNumberLn(USART1, result >> SHIFT, DEC); //pozitivna cifra } else{ //negativna cifra result = result << 8; result = ~result + 1; result = result >> 8; printNumberLn(USART1, -result >> SHIFT, DEC); }*/ //printNumberLn(USART1, MAX11210_meas_status(), DEC); }
int runVegas(void) { int i; double sd; double avgi; char mess[25]; FILE * iprt = NULL; int mode=1; void * pscr=NULL; static int n_Line=0; if(blind) vegas_control=NULL; else vegas_control=infoLine; i=imkmom(inP1,inP2); if(veg_Ptr&&veg_Ptr->dim!=i)clearGrid(); if(!veg_Ptr) veg_Ptr=vegas_init(i,func_,50); if(nin_int == 2) strcpy(mess, "Cross section[pb]"); else strcpy(mess, " Width[Gev] "); /* ** save current session parameters */ w_sess__(NULL); /* ** open protocol and resulting files */ { char fname[50]; sprintf(fname,"%sprt_%d",outputDir,nSess); iprt=fopen(fname,"a"); } /* ** initkinematics */ while(correctHistList()) editHist(); if(integral.old) { if(!n_Line) n_Line=9;} else { w_sess__(iprt); n_Line=8; } /* *** Main cycle */ for(;;) { int fz; char strmen[]="\030" " nSess = N2_1 " " nCalls = N1_1 " " Set Distributions " "*Start integration " " Display Distributions " " Clear statistic " " Freeze grid OFF " " Clear grid " " Event Cubes NCUBE " " Num. of events=NE " " Generate Events "; if(integral.freeze) { fz=1; improveStr(strmen,"OFF","ON"); improveStr(strmen,"NCUBE","%d",EventGrid); } else { fz=0; strmen[ 030*8+2]=0; } improveStr(strmen,"N1_1","%d",integral.ncall[fz]); improveStr(strmen,"N2_1","%d",integral.itmx[fz]); improveStr(strmen,"NE","%d",nEvents); menu1(54,7,"",strmen,"n_veg_*",&pscr,&mode); switch(mode) { case 0: w_sess__(NULL); if(iprt) fclose(iprt); return 0; case 1: correctInt(50,12,"Enter new value ", integral.itmx+fz,1); break; case 2: correctLong(50,12,"Enter new value ",integral.ncall+fz,1);break; case 3: editHist(); break; case 4: if(veg_Ptr->fMax && !integral.freeze) { free(veg_Ptr->fMax); veg_Ptr->fMax=NULL; veg_Ptr->evnCubes=0; } if(!veg_Ptr->fMax && integral.freeze) { setEventCubes(veg_Ptr, EventGrid); EventGrid=veg_Ptr->evnCubes; } for (i = 1; i <= integral.itmx[fz]; ++i) { char errtxt[100]=""; long nCall; if(integral.ncall[0]==0) break; negPoints=0; badPoints=0; hFill=1; nCall=vegas_int(veg_Ptr, integral.ncall[fz],1.5*(!fz),nPROCSS,&avgi, &sd); if(nCall<0) { messanykey(10,10,"NaN in integrand"); break;} if(nCall==0) break; integral.old=1; negPoints/=nCall; badPoints/=nCall; integral.nCallTot+=nCall; scrcolor(FGmain,BGmain); printLn(iprt,&n_Line,"%4d %12.4E %10.2E %8d %s", ++integral.n_it, avgi,avgi? 100*sd/(double)fabs(avgi):0.,nCall,effInfo()); if(negPoints<0) sprintf(errtxt+strlen(errtxt)," Negative points %.1G%%;", -100*negPoints/(avgi-2*negPoints)); if(badPoints) sprintf(errtxt+strlen(errtxt), "Bad Precision %.1G%%;",100*badPoints/(avgi-2*negPoints)); if(errtxt[0]) { scrcolor(Red,BGmain); printLn(iprt,&n_Line,"%s",errtxt); } integral.s0+=sd*sd; integral.s1+=avgi; integral.s2+=avgi*avgi; } integral.In=integral.s1/integral.n_it; integral.dI=sqrt(integral.s0)/integral.n_it; if(integral.n_it<=1 || integral.s0==0 ) integral.khi2=0; else integral.khi2=(integral.s2-integral.s1*integral.s1/integral.n_it)*integral.n_it/(integral.n_it-1)/fabs(integral.s0); scrcolor(FGmain,BGmain); printLn(iprt,&n_Line," < > %12.4E %10.2E %8d %7.7s %-7.1G" , integral.In, fabs(integral.In)? 100*integral.dI/(double)fabs(integral.In):0., integral.nCallTot, effInfo(), integral.khi2); if(histTab.strings) { char fname[20]; FILE * d; sprintf(fname,"distr_%d",nSess); d=fopen(fname,"w"); wrt_hist2(d,Process); fclose(d); } messanykey(54,11,"Integration is over"); /* integral.freeze=0; */ break; case 5: showHist(54,10,Process); break; case 6: clearStatistics(-1); messanykey(54,13,"Old results for integral\n" "and distributions\nare deleted."); break; case 7: if(veg_Ptr->fMax && integral.freeze) { if(mess_y_n(15,15,"You have event generator prepared.\n" " Setting the flag \"OFF\" will destroy it." " Press 'Y' to confirm.")) integral.freeze=0; } else integral.freeze=!integral.freeze; break; case 8: if(!integral.freeze || mess_y_n(15,15,"The information for Event Generator will be lost\n OK?")) { int ndim=veg_Ptr->dim; vegas_finish(veg_Ptr); veg_Ptr=vegas_init(ndim,func_,50); messanykey(57,11,"OK"); } break; case 9: if(correctLong(50,12,"Enter new value ",&EventGrid,1)) { if(veg_Ptr->fMax) {free(veg_Ptr->fMax); veg_Ptr->fMax=NULL;} printf("EventGrid=%d\n",EventGrid); setEventCubes(veg_Ptr, EventGrid); EventGrid=veg_Ptr->evnCubes; } break; case 10: correctInt(50,15,"",&nEvents,1); break; case 11: if( !veg_Ptr || !veg_Ptr->fMax) { char * mess="Before event generation one has to launch Vegas session with freezed grid\n" "to prepare generator"; if(blind) { printf("%s\n",mess); sortie(200);} else messanykey(4,13,mess); } else runEvents(); } } }
int main(void) { uint32_t stop_time; uint32_t start_time; RCC_ClocksTypeDef RCC_Clocks; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); systick_millis_init(); UART_Init(); timer7_us_init(); delay_us_init(); //LEDS gpio_pinSetup(GPIOC, GPIO_Pin_8, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_Speed_40MHz); GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_SET); //CLOCK OUTPUT PA8 gpio_pinSetup_AF(GPIOA, GPIO_Pin_8, GPIO_AF_MCO, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_Speed_40MHz); RCC_MCOConfig(RCC_MCOSource_SYSCLK, RCC_MCODiv_1); printLn(); printStringLn("------------------------------------------------"); printStringLn("System initialized."); RCC_GetClocksFreq(&RCC_Clocks); printString("SYSCLK_Frequency: "); printNumberLn(RCC_Clocks.SYSCLK_Frequency, DEC); printString("HCLK_Frequency: "); printNumberLn(RCC_Clocks.HCLK_Frequency, DEC); printString("PCLK1_Frequency: "); printNumberLn(RCC_Clocks.PCLK1_Frequency, DEC); printString("PCLK2_Frequency: "); printNumberLn(RCC_Clocks.PCLK2_Frequency, DEC); printString("SYSCLKSource: "); printNumberLn(RCC_GetSYSCLKSource(), DEC); printString("PRESCALER TIM2: "); printNumberLn(TIM_GetPrescaler(TIM3), DEC); printStringLn("------------------------------------------------"); while (1) { GPIO_ToggleBits(GPIOC, GPIO_Pin_8); TIM_SetCounter(TIM7, 0); TIM_Cmd(TIM7, ENABLE); start_time = TIM_GetCounter(TIM7); delay_us(25); stop_time = TIM_GetCounter(TIM7); TIM_Cmd(TIM7, DISABLE); printNumberLn(stop_time - start_time, DEC); delay(100); printNumberLn(millis(), DEC); } }
void printFloatLn(double number){ printFloat(number); printLn(); }
void genReadln(Symbol * s){ int endBuffer = tempEnd; tempEnd+=259; fprintf (asm_file," mov dx,offset DS:[%d] ;buffer temporario\n",endBuffer); fputs (" mov al, 0FFh ;tamanho máximo da string de 255 char\n",asm_file); fprintf (asm_file," mov ds:[%d], al\n",endBuffer); fputs (" mov ah, 0Ah\n",asm_file); fputs (" int 21h\n",asm_file); int rotInicio = ++rotCount; fprintf (asm_file," mov di, offset DS:[%d] ;posição do string\n",endBuffer+2); fprintf (asm_file," R%d:\n",rotInicio); fputs (" add di, 1 ;incrementar o contador\n",asm_file); fputs (" mov bl, ds:[di] ;caractere\n",asm_file); fputs (" cmp bl, 0dh;extende o sinal\n",asm_file); fprintf(asm_file," jne R%d ;continuar até achar o eot end of tape\n",rotInicio); fputs(" mov al ,24h\n",asm_file); fputs(" mov DS:[di],al\n",asm_file); if (compareTokenType(s,"string")) s->adress = endBuffer+2; else{ int rotInicio= ++rotCount; int rotLoop= ++rotCount; int rotFim= ++rotCount; fprintf (asm_file," mov di,offset DS:[%d] ;buffer temporario\n",endBuffer+2); fputs(" mov ax, 0 ;acumulador\n",asm_file); fputs(" mov cx, 10 ;base decimal\n",asm_file); fputs(" mov dx, 1 ;valor sinal +\n",asm_file); fputs(" mov bh, 0 \n",asm_file); fputs(" mov bl, ds:[di] ;caractere\n",asm_file); fputs(" cmp bx, 2Dh ;verifica sinal\n",asm_file); fprintf(asm_file," jne R%d ;se não negativo\n",rotInicio); fputs(" mov dx, -1 ;valor sinal -\n",asm_file); fputs(" add di, 1 ;incrementa base\n",asm_file); fputs(" mov bl, ds:[di] ;próximo caractere\n",asm_file); fprintf(asm_file," R%d:;se não negativo\n",rotInicio); fputs(" push dx ;empilha sinal\n",asm_file); fputs(" mov dx, 0 ;reg. multiplicação\n",asm_file); fprintf(asm_file," R%d: ;se não negativo\n",rotLoop); fputs(" cmp bx, 24h ;verifica fim string\n",asm_file); fprintf(asm_file," je R%d ;salta se fim string\n",rotFim); fputs(" imul cx ;mult. 10\n",asm_file); fputs(" add bx, -48 ;converte caractere\n",asm_file); fputs(" add ax, bx ;soma valor caractere\n",asm_file); fputs(" add di, 1 ;incrementa base\n",asm_file); fputs(" mov bh, 0\n",asm_file); fputs(" mov bl, ds:[di] ;próximo caractere\n",asm_file); fprintf(asm_file," jmp R%d ;loop\n",rotLoop); fprintf(asm_file," R%d: ;loop\n",rotFim); fputs(" pop cx ;desempilha sinal\n",asm_file); fputs(" imul cx ;mult. sinal\n",asm_file); tempEnd -= 259;//liberar o espaço da string if (compareTokenType(s,"integer")) fprintf(asm_file," mov ds:[%d],ax ;atribuição\n", s->adress); else fprintf(asm_file," mov ds:[%d],al ;atribuição\n", s->adress); } printLn(); }