char *multiply(char *multiplier, char *multiplicand) { int num1_length = strlen(multiplier); int num2_length = strlen(multiplicand); char *num1 = (char *)malloc(sizeof(char) * (num1_length + 1)); char *num2 = (char *)malloc(sizeof(char) * (num2_length + 1)); char *result = (char *)calloc(sizeof(char), num1_length + num2_length + 1); memcpy(num1, multiplier, num1_length + 1); memcpy(num2, multiplicand, num2_length + 1); turnaround(num1); turnaround(num2); int i,j,carry = 0,tem_num1,tem_num2; for(i = 0;i < num2_length;i ++){ for(j = 0;j < num1_length;j ++){ tem_num1 = num1[j] - '0'; tem_num2 = num2[i] - '0'; result[j + i] += (tem_num2 * tem_num1) % 10 + carry; carry = tem_num2 * tem_num1 > 9? tem_num2 * tem_num1 / 10 : 0; while(result[j + i] > 9){ //tem_num1 * tem_num2 <= 9 && tem_num1 * tem_num2 + carry > 9 carry += 1; result[j + i] -= 10; } } int e = 0; while(carry){ //i == num2_length result[j + i + e] += carry; if(result[j + i + e] > 9){ result[j + i + e] -= 10; carry = 1; }else carry = 0; e += 1; } } //change the result from Hexadecimal to string for(i = 0;i < num1_length + num2_length;i ++) result[i] += '0'; //clear the end '0' char *p2mymulend = result + strlen(result) - 1; while(*p2mymulend == '0'){ *p2mymulend-- = 0x00; if(p2mymulend - result == 0) break; } if(num1) free(num1); if(num2) free(num2); turnaround(result); return result; }
int main() { int i,n,j,t,av=0; float avg; printf("Enter the no of process="); scanf("%d",&n); struct process p[n]; for(i=0;i<n;i++) { j=i+1; printf("For %d process:\n",j); printf("Arrival time="); scanf("%d",&p[i].arrival); printf("CPU Burst time="); scanf("%d",&p[i].burst); } sort(p,n); print(p,n); for(i=0;i<n;i++) { j=turnaround(p,i); printf("Turnaround time=%d\n",j); } for(i=0;i<n;i++) { av=av+time(p,i); } avg=(float)av/n; printf("Average waiting time=%f\n",avg); }
void Swdp::seq_out (uint32_t MS, int ticks) { turnaround (false); while(ticks--) { bit_out (MS & 1); MS >>= 1; } }
task main() { acceleration(5); wait1Msec(1000); acceleration(15); wait1Msec(1000); turnaround(20, 'p'); wait1Msec(1000); turnaround(10, 'u'); wait1Msec(1000); turnaround(30, 't'); wait1Msec(1000); square(10); wait1Msec(1000); square(25); wait1Msec(1000); circle(10); wait1Msec(1000); circle(20); }
void Swdp::seq_out_parity (uint32_t MS, int ticks) { uint32_t parity = 0; turnaround (false); while (ticks--) { bit_out (MS & 1); parity ^= MS; MS >>= 1; } bit_out (parity & 1); }
uint32_t Swdp::seq_in (int ticks) { uint32_t index = 1; uint32_t ret = 0; turnaround (true); while (ticks--) { if (bit_in ()) ret |= index; index <<= 1; } return ret; }
void _3DTree::rule1(int i) { if (i == 0) drawline(); else { rule1(i - 1); glPushMatrix(); turnright(); pitchdown(); rollleft(); rule1(i - 1); glPopMatrix(); glPushMatrix(); rollleft(); turnleft(); turnleft(); pitchdown(); rule1(i - 1); glPopMatrix(); turnaround(); turnaround(); rule1(i - 1); glPushMatrix(); turnright(); turnright(); pitchdown(); rollright(); rule1(i - 1); glPopMatrix(); glPushMatrix(); turnleft(); pitchdown(); rule1(i - 1); glPopMatrix(); } }
bool Swdp::seq_in_parity (uint32_t* ret, int ticks) { uint32_t index = 1; uint32_t parity = 0; *ret = 0; turnaround (true); while (ticks--) { if (bit_in ()) { *ret |= index; parity ^= 1; } index <<= 1; } if (bit_in()) parity ^= 1; return (bool) parity; }
void Swdp::reset (void) { turnaround (false); /* 50 clocks with TMS high */ for (int i = 0; i < 50; i++) bit_out (true); }