Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include <stdio.h> // Su dung ham printf va scanf #include <conio.h> // su dung getch() #include <math.h> // su dung ham tinh toan de tinh cac bai toan trong mang 2 chieu //==========Ket thuc khai bao thu vien =======================// //===============Ham con================================// /* Bai tap tinh toan tren mang 2 chieu goi chung la ma tran (matrix 1-2-3) Input: Nhap mang 2 chieu doi da 50x50 so nguyen co N hang va M cot, a[NxM] Output: Lam nhung tac vu sau: - Tinh tong toan bo matrix. - Tinh tong cua tung dong, tinh tong cua tung cot. - Tinh tong duong cheo cua ma tran neu la ma tran vuong - Tim trong ma tran phan tu nao la so nguyen to. - Gia su co ma tran filter kich thuoc mx1 toan so 1: k[1,1,1,1,1.....,1]. Nhan ma tran a[NxM]*k[Mx1] = b[Nx1]. Tinh b. */ //=======Nhap 2 kich thuoc chieu cua mang =========================// void NhapKichThuocMang( int &n, int &m ) { n = 0 ; m =0 ; // khoi tao n va m gia tri la 0 de dieu kien while dung ngay tu dau while ( n<= 0 || m <= 0 ) // Dieu kien de phai nhap n va m la ca 2 so deu > 0 { if( n<=0 ) // trong truong hop n <= 0 thi bat nhap lai n { printf("\nMoi ban nhap n, chieu ngang cua ma tran: " ); scanf("%d",&n); } else // trong truongf hop m <= 0 thi bat nhap lai m { printf("\nMoi ban nhap m, chieu doc cua ma tran: " ); scanf("%d",&m); } } } //===============Ham nhap mang 2 chieu voi n m la hang va cot cho truoc=======================// void NhapMang2Chieu( int a[50][50], int n, int m ) { for( int i = 0; i < n ; i++ ) // i di theo n, duyet theo tung hang { for ( int j = 0 ; j< m; j++) // j theo m nen trong moi hang se duyet tung cot trong hang do { printf("\nMoi ban nhap a[%d][%d]: ",i,j); scanf("%d", &a[i][j]); } } } //==============================ham xuat ma tran ===============================// void XuatMang2Chieu( int a[50][50], int n, int m ) { printf("\n Noi dung ma tran :\n"); for (int i = 0;i < m; i ++)// i di theo n, duyet theo tung hang { for ( int j = 0 ; j< n; j++)// j theo m nen trong moi hang se duyet tung cot trong hang do printf("\t%d",a[i][j]); printf ("\n"); } } void XuatTongTheoDongvaCot( int a[50][50], int n , int m ) { int S; // Tinh theo COT for( int i = 0 ; i < n ; i++ ) { /// tuong ung voi tung dong. Se cong tong tat ca gia tri trong dong do S = 0; // Day la bien Tong cua dong thu i tuong ung // bien S dat trong for de moi dong tuong ung se reset S=0 lai tu dau for( int j = 0 ; j < m ; j++ ) // duyet tung phan tu trong day i { S= S + a[i][j]; // cong don vao bien S } /// Cho nay da ket thuc qua trinh tinh tong dong thu i printf("\nTong cua dong %d la: %d",i , S); } //void XuatTongTheoDongvaCot( int a[50][50], int n , int m ) // Tinh theo hang. for( int j = 0 ; j < n ; j++ ) { /// tuong ung voi tung dong. Se cong tong tat ca gia tri trong dong do S = 0; // Day la bien Tong cua dong thu i tuong ung // bien S dat trong for de moi dong tuong ung se reset S=0 lai tu dau for( int i = 0 ; i< m ; i++ ) // duyet tung phan tu trong day i { S= S + a[i][j]; // cong don vao bien S } /// Cho nay da ket thuc qua trinh tinh tong dong thu i printf("\nTong cua dong %d la: %d",j , S); } int Q=0; for(int i=0 ; i<n ; i++) { for( int j = 0 ; j < m ; j++ ) { Q=Q+ a[i][j]; } } printf("\nTong cua mang 2 chieu la: %d",Q); } //=====================Tongduongcheomatran=======================// void TongDuongCheoMaTran( int a[50][50], int n, int m ) { int s=0; if(n!=m ) printf("\n Khong Vuong Khong Choi"); for(int k = 0; k <=m; k++) { long s = s + a[k][k]; } printf("\nTong cua duong cheo la: %ld", s); } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// //++++++++++++++HAM MAIN+++++++++++++++++++++++++++++++++++++++++++++++// int main(int argc, char** argv) { int a[50][50]; // mang 2 chieu ten a, co kich thuoc toi da la 50 hang va 50 cot int n = 0, m= 0;// n la hang cua ma tran, m la cot cua ma tran NhapKichThuocMang( n, m ); NhapMang2Chieu( a ,n ,m ); XuatMang2Chieu(a , n , m); XuatTongTheoDongvaCot(a , n , m); TongDuongCheoMaTran(a , n , m); getch(); // su dung de dung man hinh kem tra ket qua return 0; }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत