Advertisement
diegoaguilar

Practica3

Feb 16th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1.  
  2. // Programa que suma dos vectores
  3. #include<stdio.h>
  4. class Vector
  5. {
  6. int c[10];
  7. int e;
  8. public:
  9.     void inicia (void);
  10.     void pon_dato(int i);
  11.     void suma(Vector x, Vector y );
  12.     void Visualizar(void);
  13. } ;
  14.  
  15. Vector r;
  16.  
  17. void Vector::inicia(void)
  18. {
  19.  e=0;
  20. }
  21.  
  22. void Vector::pon_dato(int i)
  23. {
  24. c[e++]=i;
  25. }
  26.  
  27.  
  28.  
  29. void Vector::Visualizar(void)
  30. {
  31.  int j;
  32.  for(j=0;j<e;j++)
  33.   printf("%d",c[j]);
  34. }
  35.  
  36. void Vector::suma(Vector x, Vector y)
  37. {
  38.   int j;
  39.   if (x.e != y.e)
  40. printf( "No se pueden sumar los vectores");
  41.   else  
  42.    for(j=0;j<x.e;j++)
  43.         r.c[j] = x.c[j]+y.c[j];
  44.    r.e=x.e;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement