main(){ unsigned short base = 1; unsigned short power = 1; unsigned short menuAnswer = 0; int userInput = 0; menuAnswer = powerMenu(); while (menuAnswer != 4){//while the user has not selected "Exit Program" if (menuAnswer == 1){//if user selects change base printf("Please enter a base between 1 and 25:"); userInput = getNum(); if (checkRange(userInput, kBaseMax, kMinNum)){ base = userInput; } } else if (menuAnswer == 2){//if user selects change exponant printf("Please enter a exponent between 1 and 5:"); userInput = getNum(); if (checkRange(userInput, kPowerMax, kMinNum)){ power = userInput; } } else if (menuAnswer == 3){//if user selects "Display base raised to exponents" printf("%d to the power %d = %d", base, power, calculation(base, power)); } menuAnswer = powerMenu();//Get menu selection from user } return 0; }
int main() { input(); s_alph(); generation(); calculation(); output(); return 0; }
DWORD WINAPI startThread(LPVOID lpParam) { int sock = *(int*)lpParam; char mesg[BUFLEN]; while(1) { char answer[BUFLEN]; bzero(mesg, sizeof(mesg)); my_read(sock, mesg, BUFLEN); calculation(mesg,answer); my_write(sock, answer, strlen(answer)); printf("%s\n",answer); } }
int main(void) { /*delcared array*/ int array[15] = {39, 50, 52, 35, 98, 95, 63, 47, 82, 9, 100, 39, 87, 2, 33}; int i; /*loop variable*/ int trueFalse; /*true false variable*/ for( i = 0; i < 15; i++) { /*will loop 15 times to print the array*/ printf("%d ", array[i]); } printf("\n"); for ( i = 0; i < 15; i++) { /*calls calc(), which will return a value based on the passed value*/ trueFalse = calculation( &array[i] ); switch ( trueFalse ) { /*handles if return of the function*/ case TRUE: printf("True "); break; case FALSE: printf("False "); break; } } printf("\n"); for( i = 0; i < 15; i++) { /*prints the array again*/ printf("%d ", array[i]); } printf("\n"); return 0; }
int main(){ int *pixel=malloc(sizeof(int)*MAX_PIXEL); int *pixelNum=malloc(sizeof(int)*MAX_PIXEL); int *numInputs=malloc(sizeof(int)*MAX_PIXEL); int *total=malloc(sizeof(int)*MAX_PIXEL); int *totalPix=malloc(sizeof(int)*MAX_PIXEL); int i; for(i=0;i<MAX_PIXEL;i++){ pixel[i]=0; pixelNum[i]=0; numInputs[i]=0; total[i]=0; totalPix[i]=0; } getInputs(numInputs,pixel,pixelNum,total,totalPix); printf("%p\n",pixel); calculation(numInputs,pixel,pixelNum,total,totalPix); printf("%p\n",pixel); printOutput(numInputs,pixel,pixelNum,totalPix); return 0; }
// Do our list content drawing here (what we see when the list is collapsed, for cObjType_DropList only) bool oFontDropDown::drawListContents(EXTListLineInfo *pInfo, EXTCompInfo* pECI) { // Draw our text if (pInfo->mLine > 0) { EXTfldval * calcFld; EXTfldval fval; ECOgetProperty(mHWnd,anumListCalc,fval); qstring calculation(fval); calcFld = newCalculation(calculation, pECI); if (calcFld != NULL) { EXTfldval result; calcFld->evalCalculation(result, pECI->mLocLocp, NULL, qfalse); qstring text(result); GDItextSpecStruct textSpec = mCanvas->textSpec(); str255 fontName; qpoint leftTop(pInfo->mLineRect.left+10, pInfo->mLineRect.top); #ifndef iswin32 leftTop.h += 2; #endif // get our font name EXTfldval fontNameFld; str255 fontNameStr; pInfo->mListPtr->getColVal(pInfo->mLine, mFontColumn, fftCharacter, 0, fontNameFld); fontNameFld.getChar(fontNameStr); GDIsetFontName(&textSpec.mFnt, fontNameStr.cString(), fontNameStr.length()); // and draw our text mCanvas->drawText(text.cString(), leftTop, textSpec); delete calcFld; }; }; return true; };
int main(int c, char **v) { int ret = 0; double result = 0.0; if(c != 2) usage(-1); assert(v[1]); expression = v[1]; stack = NEW_STACK(STACK_SIZE); ret = calculation(&result); if(ret) { printf("calculation failed, ret = %d\n", ret); DESTROY_STACK(stack); return ret; } printf("%lf\n",result); DESTROY_STACK(stack); return 0; }
int main() { struct stack_t operand_stack; char math_expression[EXPRESSION_SIZE]; int result; //fgets(math_expression, EXPRESSION_SIZE, stdin); string_input(math_expression); stack_init(&operand_stack); result = calculation(&operand_stack,math_expression); if(result == INT_MIN) { printf("Insufficient values entered!\n"); } else if(result == INT_MAX) { printf("Too many values entered!\n"); } else { printf("%d\n",result); } stack_destroy(&operand_stack); return 0; }
int main(int argc, char* argv[]) { int x, y; char buffer[255]; FILE* file; int iteration = 0; int progress = -1; int add_headers = 0; double timer; clock_t start; if (argc < 7) { printf("Usage: %s screen_width screen_height wire_width wire_height wire_mili_voltage iteration_limit\n", argv[0]); return 1; } initialize_globals(argv); d("Simulating MPI world"); available_processes = 1; process_number = 0; wire_shift_x = (screen_width - wire_width) / 2; wire_shift_y = (screen_height - wire_height) / 2; process_board_x = sqrt(available_processes); process_board_y = available_processes / process_board_x; process_x = process_number % process_board_x; process_y = process_number / process_board_x; // printf("My rank: %d.\nMy location: %d:%d (board size: %d:%d)\n", process_number, process_x, process_y, process_board_x, process_board_y); if (process_number >= process_board_x * process_board_y) { printf("I'm out of board. Should never happen!\n"); finalize(); return 0; } d("Initiate data storage%s", "."); segment_size_x = screen_width / process_board_x + 2; segment_size_y = screen_height / process_board_y + 2; data = (double*) malloc(sizeof(double) * segment_size_x * segment_size_y); if (0 == process_number) { print_board(); } for (y = 0; y < segment_size_y; ++y) { for (x = 0; x < segment_size_x; ++x) { data[y * segment_size_x + x] = initial_voltage(x, y); } } d("Register custom MPI type (not applicable)%s", "."); start = clock(); communicate(iteration); while (iteration < iteration_limit) { d("Iterations start%s", "."); calculation(iteration); communicate(iteration); ++iteration; if (process_number == 0 && 100 * iteration / iteration_limit > progress) { progress = 100 * iteration / iteration_limit; display_progress(progress, 80); // printf("Progress: %d%% (%d of %d)\n", 5 * progress, iteration, iteration_limit); } } if (0 == process_number) { printf("\n"); } timer = (double) (clock() - start) / CLOCKS_PER_SEC; // Dump data from each process. sprintf(buffer, "data-%dx%d.txt", process_x, process_y); file = fopen(buffer, "w"); for (y = 1; y < segment_size_y - 1; ++y) { for (x = 1; x < segment_size_x - 1; ++x) { fprintf(file, "%f\t%f\t%f\n", 1.0 * (process_x * (segment_size_x - 2) + x) / screen_width, 1.0 * (process_y * (segment_size_y - 2) + y) / screen_height, data[y * segment_size_x + x] ); } fprintf(file, "\n"); } fclose(file); // Log program response. if (process_number == 0) { printf("Board size: %dx%d, iterations limit: %d, used processes: %d, elapsed time: %f\n", screen_width, screen_height, iteration_limit, available_processes, timer); if (file_exists("results.txt") == 0) { add_headers = 1; } file = fopen("results.txt", "a+"); if (add_headers) { fprintf(file, "W\tH\tmax\tproc\tT\n"); } fprintf(file, "%d\t%d\t%d\t%d\t%f\n", screen_width, screen_height, iteration_limit, available_processes, timer); fclose(file); } finalize(); return 0; }
int main(int argc, char *argv[]) { if((argc < 4)|(argc > 5)) { printf(MSG_PARAMETER); return 1; } Parameter *params; if((params = (Parameter*) calloc(1, sizeof(Parameter))) == NULL) { printf(MSG_OOM); return 2; } setStandard(params, strtof(argv[1],NULL), strtof(argv[2],NULL)); if(argc == 5) { readConfig(argv[4], params); } else { printf(MSG_CONFIG); } char *bmp_name = argv[3]; int **points; if(params->v_speed <= 0) { printf(MSG_SPEED); return 4; } if((points = (int **) malloc(sizeof(int) * 20)) == NULL) { printf(MSG_OOM); return 2; } if((points[0] = (int *)realloc(NULL, sizeof(int)*10)) == NULL) { printf(MSG_OOM); return 2; } if((points[1] = (int *)realloc(NULL, sizeof(int)*10)) == NULL) { printf(MSG_OOM); return 2; } points[0][0] = params->width / 2; points[1][0] = params->height / 2; int counter = 0; if(calculation(points, &counter, params) == 2) return 2; int drawreturn = 0; if((drawreturn = drawBitMap(bmp_name, points, &counter, params)) == 3) return 3; else if(drawreturn == 2) return 2; free(points); return 0; }