Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
zeroout
//g++ 7.4.0 //write and test a function that zeros out the diagonals of a 2-dimensional square array of ints //this code is created by Rezaul Hoque on June 29,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> using namespace std; void zeroout(int [][5], int); void zeroout(int a[][5],int m){ int i,j; for(i=0;i<m;i++){ for(j=0;j<m;j++){ if(i==j ||i+j==m-1)//when both i and j are same or sum of i and j is equal to one less the size of array(i.e. a[0][0],a[1][1],a[2][2], a[3][3],a[4][4],a[1][3], a[3][1],a[0][4],a[4][0])put zero a[i][j]=0;} } } int main() { int m=5; int i,j; int a[5][5]={{31,32,33,34,35},{45,47,48,49,50},{11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}}; cout<<"Original array:\n"; for(i=0;i<m;i++){ for(j=0;j<m;j++){ cout<<" "<<a[i][j]; } cout<<"\n"; } zeroout(a,5); cout<<"After zero out:\n"; for(i=0;i<m;i++){ for(j=0;j<m;j++){ cout<<" "<<a[i][j]; } cout<<"\n"; } return 0; }
run
|
edit
|
history
|
help
0
Web Browser History
queueArray
function pointer overload
Right view of a tree
Dar
iviewb
Dar
proga2
C++ Solar eclipse program(Shoushi integrated) 1644 - 1785 from Ideone( Date: August 14, 2014 )
2