double
Statistic::ordonnee(QVector<double> &Xi,QVector<double> &Yi,int n)
{
    double b = moyenne(Yi,n) - ( pente(Xi,Yi,n) * moyenne(Xi,n) );

    return (b);
}
double HrPwWindow::variance(QVector<double> &val,int n)
{
	double sce;

	produittab(val,val,n);
	sce = moyenne(tab_temp,n) - ( moyenne(val,n) * moyenne(val,n));

  	return (sce);
}
double HrPwWindow::covariance(QVector<double> &Xi, QVector<double> &Yi,int n)
{
	double cov;

	produittab(Xi,Yi,n);
	cov = moyenne(tab_temp,n) - ( moyenne(Xi,n) * moyenne(Yi,n) );

	return (cov);
}
Beispiel #4
0
int main(){

	int nb_etudiants=0,i;
	int * notes;
	
	do{
		printf("Entrez le nombre d'étudiants : ");
		scanf("%i",&nb_etudiants);
		vider_buffer_stdin();
		
	}while(nb_etudiants<=0);
	
	notes=malloc(sizeof(int)*nb_etudiants);
	
	for(i=0;i<nb_etudiants;i++){
	
		do{
			printf("Saisissez la note du %i%s étudiant : ",i+1,i+1==1?"er":"ème");
			scanf("%i",&notes[i]);
			vider_buffer_stdin();
			
		}while(notes[i]<0 || notes[i]>20);
	}
	
	printf("\nMoyenne : %f\n",moyenne(notes,nb_etudiants));
	printf("Meilleure note : %i\n",max(notes,nb_etudiants));
	printf("Plus mauvais note : %i\n",min(notes,nb_etudiants));
	printf("Nombre de reçus : %i\n",nbrecus(notes,nb_etudiants));
	printf("Pourcentage de reçus : %f%\n",prc_recus(notes,nb_etudiants));
	
	free(notes);
	
	return EXIT_SUCCESS;
}
Beispiel #5
0
int main()
{
	vector<double>	notes;
	double			k;

	notes.push_back(12.5);
	notes.push_back(19.5);
	notes.push_back(6);
	notes.push_back(12);
	notes.push_back(14.5);
	notes.push_back(15);

	k = moyenne(notes, notes.size());
	cout << k;
	return 0;
}
Beispiel #6
0
// *****************************************************************************
//
// main
//
// Fonction pilote pour les exercices, elle demande à l'utilisateur d'entrer la
// taille d'un tableau, les cases d'un tableau puis un nombre, et exécute les
// fonctions définies plus haut sur ces entrées.
//
// *****************************************************************************
int main()
{
    printf("Entrez la taille du tableau, puis des entiers séparés par des espaces.\n");
    printf("Entrez ensuite un entier.\n");
  
    int taille = 0;
    int valeur = 0;
  
    scanf("%d", &taille);
    if (taille < 0)
        return -1;

    int tableau[taille];
    for (int i = 0; i < taille; i++)
        scanf("%d", &(tableau[i]));
  
    scanf("%d", &valeur);
    
    printf("\n\nVous avez choisi d'entrer %d entiers : ", taille);
    for (int i = 0; i < taille; i++)
        printf("%d ", tableau[i]);

    printf("\nVous avez choisi d'entrer le nombre : %d\n\n\n", valeur);

    printf("L'étendue est : %d\n", etendue(tableau, taille));
    printf("La moyenne est : %lf\n", moyenne(tableau, taille));
    printf("Le mode est : %d\n", mode(tableau, taille));
    printf("Le plus long combo est de longueur : %d\n", comboMax(tableau, taille));

   
    if (estPalindrome(tableau, taille))
        printf("Le tableau est un palindrome.\n");
    else
        printf("Le tableau n'est pas un palindrome.\n");

    if (fouille(tableau, taille, valeur))
        printf("Le tableau contient %d.\n", valeur);
    else
        printf("Le tableau ne contient pas %d.\n", valeur);
}
Beispiel #7
0
/*
 * 
 * name: match permet de gérer les actions pour le match
 * @param
 * @return
 * 
 */
void match()
{
	int hasTurned = 0;
	printf("\r%f : Début de match !\n", timeEnd.read());
	
	// Lancement timer avant mesure de l'angle
	timeAngle.start();
	
    /*
     * Boucle de match donc on fait les actions tant que le temps
     * imparti timeEnd.read() < 90
     * read() pour un temps en seconde et renvoi un float
     * read_ms() pour un temps en miliseconde et renvoi un int
     * read_us() pour un temps en microseconde et renvoi un int
     */
    while(timeEnd.read() < 90.0)
    {	

        /*
         * On affiche sur les leds l'état des capteurs
         * 	=> allumés : pas de détection
         *  => éteint  : détection
         */
        ledGauche = !capteurGauche;
        ledDroite = !capteurDroit;
		
		if(goToDance) {
			/*
			 * Lance détection ennemi
			 */
			ultraG.startRanging();
			while (!ultraG.rangingFinished()) wait(0.01);
			remplirTab(distanceGauche,ultraG.getRange());

			ultraD.startRanging();
			while (!ultraD.rangingFinished()) wait(0.01);
			remplirTab(distanceDroit,ultraD.getRange());
			
			/*
			 * Gestion de la détection des ennemis
			 */
			if(moyenne(distanceGauche) < DISTANCE_CAPTEUR || moyenne(distanceDroit) < DISTANCE_CAPTEUR)
			{
				printf("\r%f : Ennemi détecté :o\n", timeEnd.read());
				qik.stopBothMotors();
			}
			else {
				iLikeToMoveItMoveIt();
			}
		}
		else {
			// Gestion de la pose de la fresque
			if(hasTurned)
			{
				// Lancement détection mur à scratch
				ultraM.startRanging();
				while (!ultraM.rangingFinished()) wait(0.01);
				remplirTab(distanceMilieu,ultraM.getRange());
				
				if(moyenne(distanceMilieu) < DISTANCE_FRESQUE)
				{
					printf("\r%f : Fresque détectée, on fait l'accrochage =)\n", timeEnd.read());
					qik.stopBothMotors();
					/*
					 * Dépose fresque
					 */
					qikP.setMotor1Speed(-50);
					wait(3);
					qikP.setMotor1Speed(0);
					
					// On recule, mettez les feux de recul et la sirène !
					printf("\r%f : Mettez les feux de recul et la sirène !\n", timeEnd.read());
					Timer coucouTimer;
					coucouTimer.start();
					while(coucouTimer.read() <= 4 || moyenne(distanceMilieu) <= DISTANCE_FRESQUE*2) {					
						ultraArr.startRanging();
						while (!ultraArr.rangingFinished()) wait(0.01);
						remplirTab(distanceArr,ultraArr.getRange());
						
						printf("dist. arrière : %d\n", moyenne(distanceArr));
					
						if(ultraArr.getRange() < DISTANCE_CAPTEUR)
						{
							printf("\r%f : Ennemi détecté :o\n", timeEnd.read());			
							qik.stopBothMotors();
						}
						else
						{
							reculer(1);
						}
						
						// Détection mur à scratch
						ultraM.startRanging();
						while (!ultraM.rangingFinished()) wait(0.01);
						remplirTab(distanceMilieu,ultraM.getRange());
					}
					qik.stopBothMotors();
					coucouTimer.stop();
					
					goToDance = 1;
					printf("\r%f : Dance dance mode =D\n", timeEnd.read());
				}
				else
				{
					avancer(0.80);
				}
			}
			else     
			{
				/*
				 * Lance détection ennemi
				 */
				ultraG.startRanging();
				while (!ultraG.rangingFinished()) wait(0.01);
				remplirTab(distanceGauche,ultraG.getRange());

				ultraD.startRanging();
				while (!ultraD.rangingFinished()) wait(0.01);
				remplirTab(distanceDroit,ultraD.getRange());

				/*
				 * Gestion de la détection des ennemis
				 */
				if(moyenne(distanceGauche) < DISTANCE_CAPTEUR || moyenne(distanceDroit) < DISTANCE_CAPTEUR)
				{
					printf("\r%f : Ennemi détecté :o\n", timeEnd.read());
					qik.stopBothMotors();
				}
				else {
					avancer(1);
				}
			}
			
			printf("\r%f : Angle %d sur %d \n", timeEnd.read(), cptPosition, SEUIL);
			if(!hasTurned) {
				hasTurned = (abs(cptPosition) >= SEUIL) && (abs(cptStack) >= SEUIL_STACK);
				if(hasTurned)
					printf("\r%f : On a tourné, on peut détecter la Fresque\n", timeEnd.read());
			}
				
			// Update timer angle
			if(timeAngle.read() >= ANGLE_MAX_TIMER) {
				timeAngle.stop();
				angleGo = 1;
			}
		}

    }

    qikP.setMotor1Speed(-20);
    wait(7.5);

    qikP.setMotor1Speed(0);
    qik.stopBothMotors(); 
}
int rgb_to_nb(int r, int g, int b)
{
// Si la moyenne des 3 couleurs est < 127 (moitié de 255) alors on renvoie noir (0) sinon blanc (1)
    //printf("\n%d %d %d",r,g,b);
  return (moyenne(r,g,b) < 127) ? 0 : 1;
}
double HrPwWindow::ordonnee(QVector<double> &Xi,QVector<double> &Yi,int n)
{
	double b = moyenne(Yi,n) - ( pente(Xi,Yi,n) * moyenne(Xi,n) );

	return (b);
}
Beispiel #10
0
void menu()
{
	system("cls");// efface le terminal
	printf("saisissez votre fonctions : \n");
	printf("1 : multiplication par 3 \n");
	printf("2 : division par 2 \n");
	printf("3 : moyenne de 3 nombres \n");
	printf("4 : convertion degre vers radian \n");
	int n; //variable correspondant au choix
	scanf_s("%d", &n);
	switch (n) //gère les differents cas
	{
		default : //renvoie au menu en cas de numéro inconnu
		{
			menu();
		}
		case 1 : //appelle la première fonction
		{
		system("cls"); // efface le terminal
			printf("entrez un nombre entier :");
			int nombre = 0;
			scanf_s("%d", &nombre);
			triple(nombre);
			printf("%d \n", triple(nombre));
			system("PAUSE");
			menu();
		}
		case 2 : // appelle la deuxième fonction
		{
			system("cls"); // efface le terminal
			printf("entrez un nombre entier :");
			int nombre = 0;
			scanf_s("%d", &nombre);
			division(nombre);
			system("PAUSE");
			menu();
			
		}
		case 3 : //appelle la 3eme fonction
		{
			system("cls"); // efface le terminal
			int a = 0, b = 0;
			float c = 0;
			printf("entrez le premier nombre entier : \n");
			scanf_s("%d", &a);
			printf("entrez le deuxieme entier : \n");
			scanf_s("%d", &b);
			printf("entrez un nombre reel : \n");
			scanf_s("%f", &c);
			printf("la moyenne est : %.3f \n", moyenne(a, b, c));
			system("PAUSE");
			menu();
			
		}
		case 4 : //appelle la 4eme fonction
		{
			system("cls"); // efface le terminal
			printf("entrez un angle en degres : \n");
			float deg = 0;
			scanf_s("%f", &deg);
			printf("l'angle en degré vaut : %f \n", convDegRad(deg));
			system("PAUSE");
			menu();
		}
	}
}
void regression(float Xi[],float Yi[],int N,float result[],float ProduitXiYi[],float carre_ecart_a_moyenne_Xi[],float carre_ecart_a_moyenne_Yi[])

{

  float SommeXi;
  float SommeYi;
  float MoyenneXi;
  float MoyenneYi;
  float SommeProduitXiYi;
  float SommeCarreXiMoinMoyenneXi;
  float SommeCarreYiMoinMoyenneYi;
  float a;
  float b;
  double r;
  float tab_ecart_a_moyenne[MAX];
  float ecart_a_moyenne_Xi[MAX];
  float ecart_a_moyenne_Yi[MAX];
  int i=1;

  /*Calcul de la somme des Xi et Yi*/

  SommeXi= somme(Xi,N);
  SommeYi= somme(Yi,N);

  /*Calcul des moyennes des Xi et Yi*/

  MoyenneXi = moyenne(SommeXi,N);
  MoyenneYi = moyenne(SommeYi,N);

  /*Calcul de de la pente "a"de la droite et de l'ordonee à l'origine "b" */



  /*Somme des Xi*Yi*/

  produittab(Xi,Yi,ProduitXiYi,N);
  SommeProduitXiYi = somme(ProduitXiYi,N);



  /*calcul des (Xi- MoyenneXi)² et (Yi- MoyenneYi)² */

  ecart_a_moyenne(Xi,tab_ecart_a_moyenne,MoyenneXi,N);

  i=1;
  while (i<(N+1))
    {
      ecart_a_moyenne_Xi[i] = tab_ecart_a_moyenne[i];
      carre_ecart_a_moyenne_Xi[i] = ((ecart_a_moyenne_Xi[i])*(ecart_a_moyenne_Xi[i]));i++;
    };

  ecart_a_moyenne(Yi,tab_ecart_a_moyenne,MoyenneYi,N);

  i=1;
  while (i<(N+1))
    {
      ecart_a_moyenne_Yi[i] = tab_ecart_a_moyenne[i];
      carre_ecart_a_moyenne_Yi[i] = ((ecart_a_moyenne_Yi[i])*(ecart_a_moyenne_Yi[i]));i++;
    };


  /*Somme des (Xi- MoyenneXi)²*/


  SommeCarreXiMoinMoyenneXi = somme(carre_ecart_a_moyenne_Xi,N);
  SommeCarreYiMoinMoyenneYi = somme(carre_ecart_a_moyenne_Yi,N);


  /*Appel de la fonction de calcul de la pente "a" de la droite*/


  a=pente(SommeProduitXiYi,MoyenneXi,MoyenneYi,SommeCarreXiMoinMoyenneXi,N);


  /*Appel de la fonction de calcul de l'ordonee a l'orrigine "b"*/


  b=ordonee(MoyenneXi,MoyenneYi,a);


  /*Calcul du coefficient de corrélation "r"*/

  r=corr(SommeCarreXiMoinMoyenneXi,SommeCarreYiMoinMoyenneYi,a);

  /*Stockage des résultats dans une tableau de varialbes*/

  result[0]=SommeXi;
  result[1]=SommeYi;
  result[2]=MoyenneXi;
  result[3]=MoyenneYi;
  result[4]=SommeProduitXiYi;
  result[5]=SommeCarreXiMoinMoyenneXi;
  result[6]=SommeCarreYiMoinMoyenneYi;
  result[7]=a;
  result[8]=b;
  result[9]=r;

}