int main(void) { char name[20]; double a, b; /* SET AVAILABLE FUNCTIONS */ strcpy(functiontable[0].name, "sin"); functiontable[0].f = sin; ++ functions; strcpy(functiontable[1].name, "cos"); functiontable[1].f = cos; ++ functions; strcpy(functiontable[2].name, "tan"); functiontable[2].f = tan; ++ functions; strcpy(functiontable[3].name, "log"); functiontable[3].f = log; ++ functions; strcpy(functiontable[4].name, "sqrt"); functiontable[4].f = sqrt; ++ functions; strcpy(functiontable[5].name, "sin2"); functiontable[5].f = &sin2; ++ functions; printf("Function name and parameters: "); scanf("%s %lf %lf", name, &a, &b); printf("f(a): %.2lf, f(b): %.2lf, zero: %.2lf\n", apply(name, a), apply(name, b), findzero(name, a, b)); plotfunction(name, a, b); return 0; }
/* * two-wire constructor. * Sets which wires should control the motor. */ void ATmStepper::ATmStepperInit(unsigned long step_freq_max, int motor1_pin, int motor2_pin, int motor_direction, int motor_enable, int x_lim, int y_lim) { velocity1x = 0; //set initial velocity velocity1y = 0; //set initial velocity posnew1x = 0; posnew1y = 0; pos1x = 0; pos1y = 0; running = 0; // Arduino pins for the motor control connection: _motorx_pin = motor1_pin; _motory_pin = motor2_pin; _motor_enable = motor_enable; _motor_dir = motor_direction; _x_lim = x_lim; _y_lim = y_lim; _step_freq_max = step_freq_max; // setup the pins on the microcontroller: pinMode(_motorx_pin, OUTPUT); pinMode(_motory_pin, OUTPUT); pinMode(_motor_dir, OUTPUT); pinMode(_motor_enable, OUTPUT); pinMode(_x_lim, INPUT); pinMode(_y_lim, INPUT); digitalWrite(_x_lim, HIGH); //enable pullups digitalWrite(_y_lim, HIGH); //init our timer to run at the max step speed (1000hz max) and to call the function step each time MsTimer2::set(step_freq_max, ATmStepper::step); //start the hardware timer delay(30); findzero(); }
int main(int argc, char **argv) { (void)&argc; (void)&argv; printf("%d\n", findzero(sq49)); return 0; }
void game(int a[][4],int row,int col) { int key; //key to take the navigation key as input int *z,t,i,j,k,l,p=1;//t is temp element,i j are rows and columns respectively z=findzero(a,4,4); //z takes the address of box having zero for(k=0;k<row;k++) { for(l=0;l<col;l++) //finding row and column of box having 0 { if(a[k][l]==*z) //finding zero in the array { i=k; //row found j=l; //column found } } } while(p==1) //to ensure that only 2,4,5,6,8 are entered { fflush(stdin); scanf("%d",&key); if(key==2 || key==4 || key==6 || key==8 || key==5) break; else printf("Please press 2,4,5,6 or 8 !\n"); } switch(key) { case 2: //down arrow key { t=*z; *z=a[i+1][j]; //swapping of 0 and element in down of 0 a[i+1][j]=t; printf("\n"); print(a,4,4); //printing the new matrix check(a,4,4); //checking the order break; } case 6: //right arrow key { if(i==3 && j==3) { printf("You can't throw out the blank one.\nReenter the navigation!\n"); game(a,4,4); break; } else { t=*z; *z=a[i][j+1]; //swapping of 0 and number right of it a[i][j+1]=t; printf("\n"); print(a,4,4); //printing the new matrix check(a,4,4); //checking the order break; } } case 4: //left arrow key { if(i==0 && j==0) { printf("You can't throw out the blank one.\nReenter the navigation!\n"); game(a,4,4); break; } else { t=*z; *z=a[i][j-1]; //swapping of 0 and number left to it a[i][j-1]=t; printf("\n"); print(a,4,4); //printing the new matrix check(a,4,4); //checking the order of new matrix break; } } case 8: //up arrow key { t=*z; *z=a[i-1][j]; //swapping of 0 and number up to it a[i-1][j]=t; printf("\n"); print(a,4,4); //printing the new matrix check(a,4,4); //checking the order of the new matrix break; } case 5: exit(0); } }