// Alignment // For every nearby boid in the system, calculate the average velocity Vec2f Boid::align(vector<Boid> &boids) { float neighordistance = 50; Vec2f sum = new Vec2f(0,0); int count = 0; for(int i=0; i<boids.size(); i++) { Boid other = boids[i]; float d = distance(loc, other.loc); if((d>0) && (d < neighordistance)) { //need to figure out this sum = addition(sum, other); count++; } } if(count > 0) { sum = divide(sum, count); sum = normalize(sum); sum = sum*mmaxSpeed; Vec2f steer = sub(sum , vel); if(steer < mmaxForce) { return steer; } else { return new Vec2f(0,0); } } }
// Separation // Method checks for nearby boids and steers away Vec2f Boid::separate(vector<Boid> &boids) { mflockSepWeight = 25.0f; Vec2f steer = new Vec2f(0,0,0); int count = 0; //for each boid check if it's too close for(int i=0; i<boids.size(); i++) { Boid other = boids[i]; float d = distance(loc, other.loc); if ((d>0) && (d < mflockSepWeight)) { //calculating vector pointing away from the neighbor Vec2f diff = sub(loc, boids[i]); diff = normalize(diff); diff = diff/d; steer = addition(steer, diff); count++; } } if (count > 0) { steer = divide(steer,count); } if (magnitute(steer) > 0) { steer = normalize(steer); steer = steer * mmaxSpeed; steer = steer - vel; while(steer < mmaxForce) { } } return steer; }
int main(){ int com; srand(time(NULL)); do{ com = displaymenu(); switch(com){ case 1: addition(); break; case 2: subtraction(); break; case 3: multiplication(); break; case 4: division(); break; case 5: printf("Have a nice day\n"); } }while(com != 5); //needed for all basic programs to run for the professor system("pause"); return(0); }
void emit_add_test(Seq_T stream) { emit(stream, loadval(r2, 99)); emit(stream, loadval(r3, 3)); emit(stream, addition(r1, r2, r3)); emit(stream, output(r1)); emit(stream, loadval(r1, ' ')); emit(stream, output(r1)); emit(stream, loadval(r2, 31)); emit(stream, loadval(r3, 5)); emit(stream, addition(r1, r2, r3)); emit(stream, output(r1)); emit(stream, loadval(r1, '\n')); emit(stream, output(r1)); emit(stream, halt()); }
void Camera::MoveDownward( GLfloat Distance ) { Vector3D addition(0,-Distance,0); Position = Position + addition; }
void CommandeManager::calculer(QString& chaine) throw(LogMessage){ QStringList liste = chaine.split(' ',QString::SkipEmptyParts); for(QStringList::Iterator it = liste.begin();it!=liste.end();++it){ QString current = *it; if(current.contains(QRegExp("'.*"))){ QString expr=""; do{ expr+=current; expr+=" "; it++; current = *it; } while(!current.contains(QRegExp(".*'"))); expr+=current; _pile->empilerExpression(expr); } else if(current.contains(QRegExp("^\\+$"))) addition(); else if(current.contains(QRegExp("^\\-$"))) soustraction(); else if(current.contains(QRegExp("^\\*$"))) multiplication(); else if(current.contains(QRegExp("^/$"))) division(); else{ try{ _pile->empilerConstante(_factory.getConstante(current)); } catch(LogMessage& msg){ throw; } } } }
void Camera::MoveLeft ( GLfloat Distance ) { Vector3D addition(Distance,0,0); Position = Position -RightVector * -Distance; }
int main(int argc, char* argv[]){ int x = 2; int y = 3; int z = addition(x, y); printf("%d\n", z); return 0; }
// Start of Main Program int main() { int X=1; char Calc_oprn; // Function call calculator_operations(); while(X) { printf("\n"); printf("%s : ", "Enter the calculator Operation you want to do:"); Calc_oprn=getche(); switch(Calc_oprn) { case '+': addition(); break; case '-': subtraction(); break; case '*': multiplication(); break; case '/': division(); break; case '?': modulus(); break; case '!': factorial(); break; case '^': power(); break; case 'H': case 'h': calculator_operations(); break; case 'Q': case 'q': exit(0); break; case 'c': case 'C': system("cls"); calculator_operations(); break; default : system("cls"); printf("\n**********You have entered unavailable option"); printf("***********\n"); printf("\n*****Please Enter any one of below available "); printf("options****\n"); calculator_operations(); } } }
// reduce all terms of f with leading term of g until no term of f can be cancelled // return true if a change happened, otherwise false // f is being changed to its reduction // bool BRP::reduceTail(const BRP &g) { //cout << "reduceTail: this = " << (*this) << ", by g = " << g << endl; // if ( (*this) == 0 ) { // cerr << "Called reduceTail on 0 brp" << endl; // return false; // } brMonomial lt = g.LT(); bool ret = false; monomials::iterator it = m.begin(); ++it; // really only reduce tail monomials::iterator end = m.end(); for( ; it != end; ) { brMonomial mono = *it; if (isDivisibleBy(mono,lt) ) { //cout << mono << " is divisible by " << lt << endl; addition(g*(mono^lt), it--); //cout << *this << endl; ++it; ret = true; } if (lt>mono) { // stop iterating because smaller are never divisible by larger return ret; } ++it; } //cout << "at the end of reduceTail, this = " << (*this) << endl; return ret; }
/** DEBUT BIGINT racine_carree(BIGINT); DEBUT **/ BIGINT racine_carree(BIGINT nb) { BIGINT resultat, tmp2, tmp, initial_guess; int i; initListe(&resultat); initListe(&initial_guess); initListe(&tmp); initListe(&tmp2); initial_guess = clone(nb); for(i = 0; i < (nb.nbEl / 2); i += 1) defilerListe(&initial_guess); i = 0; while(i < SQRT_HERON_THRESHOLD) { resultat = clone(initial_guess); tmp = divisionScolaire(nb, initial_guess); tmp2 = addition(tmp, initial_guess); viderListe(&tmp); viderListe(&initial_guess); initial_guess = divisionPar2(tmp2); if(comparer_nb(initial_guess, resultat) == EGAL) { i += 1; } viderListe(&resultat); viderListe(&tmp2); } return initial_guess; }
int main(int argc, char* argv[]) { int zahlen_array[MAX] = {}; int i = 0; int ergebnis = 0; int limit = 0; /* das Array mit Zahlen befüllen, wobei zahlen_array[0]=1..zahlen_araay[99]=100*/ for (i=0; i < MAX; i=i+1) zahlen_array[i] = i +1; /* Funktionsaufruf */ ergebnis = addition(zahlen_array); printf ("Die Summe aller Zahlen von 1 bis 100 ist: %d\n",ergebnis); /* Wert einlesen */ printf("Bis zu welchem Indexwert soll ausgegeben werden?"); scanf("%d", &limit); /* Prüfen ob die Eingabe Valid ist */ if (limit<=MAX) ausgabe(zahlen_array,limit); else printf ("ERROR: Index out of bound. Bitte kleiner als %d eingeben\n",MAX+1); return 0; }
jfloatArray Java_fr_bowserf_nbodyproblem_CalculationNDK_computeNewPosition(JNIEnv *env, jobject obj){ int numberCoordinates = N * 3; float *newPositions = (float*)malloc((numberCoordinates) * sizeof(float)); for(int i = 0 ; i < N ; i++){ float *acc = (float*)calloc(3, sizeof(float)); for(int j = 0 ; j < N ; j++){ float square = squaredNorm(p + i * 3, p + j * 3); float denominateur = (float) pow(square + squaredEpsilon, THREE_AND_HALF); float* resultSub = subtraction(p + i * 3, p + j * 3); float* numerateur = mult(m[j], resultSub); float* resultMult = mult(1 / denominateur, numerateur); add(acc, resultMult); free(resultSub); free(numerateur); free(resultMult); } float *tmp_v = addition(v + i * 3, mult(G, acc)); v[i * 3] = tmp_v[0]; v[i * 3 + 1] = tmp_v[1]; v[i * 3 + 2] = tmp_v[2]; float *tmp_rep = addition(v + i * 3, p + i * 3); newPositions[i * 3] = tmp_rep[0]; newPositions[i * 3 + 1] = tmp_rep[1]; newPositions[i * 3 + 2] = tmp_rep[2]; free(tmp_rep); free(acc); free(tmp_v); } for(int i = 0 ; i < numberCoordinates ; i++){ p[i] = newPositions[i]; } free(newPositions); (*env)->SetFloatArrayRegion(env, result, 0, numberCoordinates, p); return result; }
int main() { int x=2, y=3; printf("%i\n\n", addition(x,y)); printf("%i\n\n", subtraction(x,y)); printf("%i\n\n", multiplication(x,y)); printf("%f\n", division(x,y)); return 0; }
int main(int argc, char *argv[]) { std::string lhs = "-9865"; std::string rhs = "879"; auto result = addition(lhs, rhs); std::cout << result << std::endl; return 0; }
double fonctiondemerite(double*w,double *x,double t,double *d,double *G,double *tirages,double spot,double r,int N) { double *add=malloc((N+1)*sizeof(double)); double *mult=malloc((N+1)*sizeof(double)); multiplication(mult,-t,d,spot,r,N); addition(add,x,mult,spot,r,N); return fonctionnelle(w,G,tirages,add, spot, r,N); }
inline struct map_type *subtraction( struct map_type *map, struct map_type *map_2 ) { struct map_type *tmp, *result; tmp = multiplicate_on_value( -1, map_2 ); result = addition( map, tmp ); deallocate( tmp ); return result; }
int main() { int a = 9; int b = 4.5; printf("%i\n", addition(a, b)); //printf("%i\n", soustraction(a, b)); printf("%i\n", multiplication(a, b)); //printf("%f\n", division(a, b)); return 0; }
int main (void) { int a, b; a= 0x1010101; b= 0x2020202; c= 0x3030303; d= addition(&a, &b, c); return (0); }
main() { long first, second, sum; scanf("%ld%ld", &first, &second); sum = addition (first, second); printf("%ld\n", sum); return 0; }
int main() { int m = __VERIFIER_nondet_int(); int n = __VERIFIER_nondet_int(); long long result = addition(m,n); if (m < 100 || n < 100 || result >= 200) { return 0; } else { ERROR: __VERIFIER_error(); } }
int main() { int sum=0, n; printf("Please enter the value of n: "); scanf("%d", &n); addition(n, &sum); printf("The sum is %d", sum); return 0; }
int main() { int m = __VERIFIER_nondet_int(); int n = __VERIFIER_nondet_int(); int result = addition(m,n); if (result == m - n) { return 0; } else { ERROR:assert(0); goto ERROR; } }
struct timespec multiplicationEntier(struct timespec *t, int entier) { struct timespec resultat; resultat.tv_sec = 0; resultat.tv_nsec = 0; int i = 0; for(i=0;i<entier;i++) { resultat = addition(&resultat, t); } return resultat; }
int main(void) { Complexe a = {1,0}; Complexe b = {1,1}; Complexe c = {0,1}; Complexe d = {0,2}; Complexe e = {2, -3}; affiche(addition(a, c)); affiche(multiplication(c, c)); affiche(multiplication(b, b)); affiche(division(d, c)); affiche(division(e, b)); }
void do_op(char C) { switch(C) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': push(C-'0'); break; case '+': addition(); break; case '-': subtraction(); break; case '*': multiplication(); break; case '/': division(); break; case '%': modulo(); break; case '^': north(); break; case '>': east(); break; case 'V': case 'v': south(); break; case '<': west(); break; case '?': spin(); break; case '!': lnot(); break; case '`': gt(); break; case '_': hif(); break; case '|': vif(); break; case '"': tsm(); break; case ':': dup(); break; case '\\': swap(); break; case '$': chomp(); break; case '#': jump(); break; case 'p': put(); break; case 'g': get(); break; case 'H': gate(); break; case '.': print_i(); break; case ',': print_c(); break; case '&': input_i(); break; case '~': input_c(); break; case '@': hacf(); break; case '{': left_b(); break; case '}': right_b(); break; case '[': carry_l(); break; case ']': carry_r(); break; case ';': empty(); break; case 'O': portal_o(); break; case 'B': portal_b(); break; default: /* DO NOTHING! */ break; } }
// Cohesion // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location Vec2f Boid::cohesion(vector<Boid> &boids) { float neighbordist = 50; Vec2f sum = new Vec2f(0,0); int count = 0; for(int i=0; i<boids.size(); i++) { Boid other = boids[i]; float d = distance(loc, other.loc); if((d>0) && (d < neighbordist)) { //need to figure out sum = addition(sum, other); count++ } }
int main() { node *head1, *head2; int n; int i; int c, e; node *p, *q; //下面创建 list1 i = 0, p = q = head1 = NULL; scanf("%d", &n); while(233) { if(i++ >= n) break; p = (node*)malloc(sizeof(node)); scanf("%d %d", &c, &e); p->coefficient = c, p->exponent = e; if(head1 == NULL) head1 = p, q = p; else q->next = p, q = p; } if(q != NULL)q->next = NULL; //下面创建 list2 i = 0, p = q = head2 = NULL; scanf("%d", &n); while(233) { if(i++ >= n) break; p = (node*)malloc(sizeof(node)); scanf("%d %d", &c, &e); p->coefficient = c, p->exponent = e; if(head2 == NULL) head2 = p, q = p; else q->next = p, q = p; } if(q != NULL)q->next = NULL; //end of input #ifdef DEBUG puts("list1:"); print_list(head1); puts("list2:"); print_list(head2); puts("list:"); #endif node *ans = addition(head1, head2, &n); printf("%d\n",n); print_list(ans); return 0; }
void init(tab cmd){ if (!strcmp(cmd, "addition")) { int a,b; printf("Enter two integers :\n"); scanf("%d %d", &a, &b); printf("%d + %d = %d \n", a, b, addition(a, b)); } else if (!strcmp(cmd, "pgcd")) { int a,b; printf("Enter two integers :\n"); scanf("%d %d", &a, &b); printf("pgcd (%d, %d) = %d \n", a, b, pgcd(a, b)); } else if (!strcmp(cmd, "somme")) { int a; printf("Enter one integer :\n"); scanf("%d", &a); printf("Somme des %d premiers entiers = %d \n", a, somme(a)); } else if (!strcmp(cmd, "factorielle")) { int a; printf("Enter one integers :\n"); scanf("%d", &a); printf("(%d)! = %d \n", a, factorielle(a)); } else if (!strcmp(cmd, "puissance")) { float a,b; printf("Enter two floats :\n"); scanf("%f %f", &a, &b); printf("(%g ^ %g) = %g \n", a, b, puissance(a, b)); } else if (!strcmp(cmd, "isocele")) { int a; printf("Enter one integer :\n"); scanf("%d", &a); isocele(a); } else if (!strcmp(cmd, "cercle")) { int a; printf("Enter one integer :\n"); scanf("%d", &a); cercle(a); } else { printf("Command not found \n"); printf("Running listAll ... ? \n"); } return ; }
int main(int argc, char* argv[]) { if (argc < 3) { std::cout << "Please provide two numbers. Run this program as follows: ./compute a b\n"; return 0; } double sum = addition(atof(argv[1]), atof(argv[2])); std::cout << argv[1] << " + " << argv[2] << " = " << sum << "\n"; double difference = subtraction(atof(argv[1]), atof(argv[2])); std::cout << argv[1] << " - " << argv[2] << " = " << difference << "\n"; return 0; }