Advertisement
nguyenhappy92

Tích các số lẻ trong ma trận 2 chiều nguyên

Dec 20th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. // Tinh tich cac so le ma tran so nguyen
  2. // Khai bao cac ham thu vien neu co
  3. #include<stdio.h>
  4. #include<conio.h>
  5. #define SIZE 100
  6. void nhap(int a[][SIZE],int &m,int &n)
  7. {
  8. scanf("%d%d",&m,&n);
  9. for(int i=0;i<m;i++)
  10. {
  11. for(int j=0;j<n;j++)
  12. {
  13. scanf("%d",&a[i][j]);
  14. }
  15. }
  16. }
  17. long tich(int a[][SIZE],int m,int n)
  18. {
  19. long s=1;
  20. for(int i=0;i<m;i++)
  21. {
  22. for(int j=0;j<n;j++)
  23. {
  24. if((a[i][j])%2!=0)
  25. {
  26. s=s*a[i][j];
  27. }
  28. }
  29. }
  30. return s;
  31. }
  32. void main()
  33. {
  34. int a[SIZE][SIZE],m,n;
  35. nhap(a,m,n);
  36. printf("%ld",tich(a,m,n));
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement