Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. void nhap(double **arr,int dong,int cot)
  4. {
  5. for(int i=0;i<dong;i++)
  6. {
  7. for(int j=0;j<cot;j++)
  8. {
  9. scanf("%lf",*(arr+i)+j);
  10. }
  11. }
  12. }
  13. void tong(double **arr1,double **arr2,int dong,int cot)
  14. {
  15. double **arr3=(double **)calloc(dong,sizeof(double*));
  16. for(int i=0;i<dong;i++)
  17. {
  18. *(arr3+i)=(double *)calloc(cot,sizeof(double));
  19. }
  20. for(int i=0;i<dong;i++)
  21. {
  22. for(int j=0;j<cot;j++)
  23. {
  24. arr3[i][j]=arr1[i][j]+arr2[i][j];
  25. }
  26. }
  27. for(int i=0;i<dong;i++)
  28. {
  29. for(int j=0;j<cot;j++)
  30. {
  31. printf("%.2lf ",arr3[i][j]);
  32. }
  33. printf("\n");
  34. }
  35. }
  36. int main()
  37. {
  38. int dong,cot;
  39. scanf("%d%d",&dong,&cot);
  40. double **arr1=(double **)calloc(dong,sizeof(double*));
  41. for(int i=0;i<dong;i++)
  42. {
  43. *(arr1+i)=(double *)calloc(cot,sizeof(double));
  44. }
  45. nhap(arr1,dong,cot);
  46. double **arr2=(double **)calloc(dong,sizeof(double*));
  47. for(int i=0;i<dong;i++)
  48. {
  49. *(arr2+i)=(double *)calloc(cot,sizeof(double));
  50. }
  51. nhap(arr2,dong,cot);
  52. tong(arr1,arr2,dong,cot);
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement