Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void cree(int *vect1,int *vect2, int *nombre);
- void scal(int *vect1,int *vect2, int *nombre);
- void detruire(int *vect1, int *vect2 , int *nombre);
- int main(void)
- {
- int *vect1=NULL;
- int *vect2=NULL;
- int nombre;
- cree(vect1,vect2,&nombre);
- scal(vect1,vect2, &nombre);
- return 0;
- }
- void cree(int *vect1,int *vect2,int *nombre)
- {
- int i;
- printf("entrez la taille du vecteur \n");
- scanf("%d",nombre);
- vect1=(int*)malloc(*nombre*sizeof(int));
- vect2=(int*)malloc(*nombre*sizeof(int));
- for(i=0;i<*nombre;i++)
- {
- printf("entrez la valeur n %d du vecteur 1: \n",i+1);
- scanf(" %d",&vect1[i]);
- }
- for(i=0;i<*nombre;i++)
- {
- printf("entrez la valeur n %d du vecteur 2: \n",i+1);
- scanf(" %d",&vect2[i]);
- }
- }
- void scal(int *vect1,int *vect2,int *nombre)
- {
- int i;
- int S=0;
- for(i=0;i<*nombre;i++)
- {
- S=vect1[i]*vect2[i]+S;
- }
- printf("Le produit scalaire est : %d \n",S);
- }
- void detruire(int *vect1, int *vect2, int *nombre)
- {
- int i;
- for(i=0;i<*nombre;i++)
- {
- free(vect1);
- }
- for(i=0;i<*nombre;i++)
- {
- free(vect2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement