Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. void cree(int *vect1,int *vect2, int *nombre);
  6. void scal(int *vect1,int *vect2, int *nombre);
  7. void detruire(int *vect1, int *vect2 , int *nombre);
  8.  
  9.  
  10. int main(void)
  11. {
  12. int *vect1=NULL;
  13. int *vect2=NULL;
  14. int nombre;
  15.  
  16.  
  17. cree(vect1,vect2,&nombre);
  18. scal(vect1,vect2, &nombre);
  19. return 0;
  20.  
  21. }
  22. void cree(int *vect1,int *vect2,int *nombre)
  23. {
  24. int i;
  25. printf("entrez la taille du vecteur \n");
  26. scanf("%d",nombre);
  27. vect1=(int*)malloc(*nombre*sizeof(int));
  28. vect2=(int*)malloc(*nombre*sizeof(int));
  29. for(i=0;i<*nombre;i++)
  30. {
  31. printf("entrez la valeur n %d du vecteur 1: \n",i+1);
  32. scanf(" %d",&vect1[i]);
  33. }
  34. for(i=0;i<*nombre;i++)
  35. {
  36. printf("entrez la valeur n %d du vecteur 2: \n",i+1);
  37. scanf(" %d",&vect2[i]);
  38. }
  39.  
  40.  
  41. }
  42. void scal(int *vect1,int *vect2,int *nombre)
  43. {
  44. int i;
  45. int S=0;
  46. for(i=0;i<*nombre;i++)
  47. {
  48.  
  49.  
  50. S=vect1[i]*vect2[i]+S;
  51.  
  52. }
  53. printf("Le produit scalaire est : %d \n",S);
  54.  
  55.  
  56. }
  57. void detruire(int *vect1, int *vect2, int *nombre)
  58. {
  59. int i;
  60. for(i=0;i<*nombre;i++)
  61. {
  62. free(vect1);
  63. }
  64. for(i=0;i<*nombre;i++)
  65. {
  66. free(vect2);
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement