/************* Creates a spiral matrix square or rectangular .************/
/* It first finds all the indices where items are to be placed. After one iteration of the 4 loops, matrix size is reduced. "Start" variable points to the lcation from where the filling has to start */
typedef struct { int m,n; }Index;
int Create_Spiral_Matrix ( int Linear[],int Size ) { int **Spiral; int m = 0 ,n = 0, p = m , q = n, i; int c = 0, Start = 0; Index *I;
while ( m*n != Size ) { printf("nFeed in the dimensions of the Spiral Matrix to be formed := "); scanf("%d %d",&m,&n); } p = m; q = n;
Spiral = (int **) malloc( m * sizeof(int *)); //Check Mem Allocation To Prevent Crash. for ( i = 0; i < m; i++) Spiral[i] = (int *) malloc( m * sizeof(int)); //Check Mem Allocation To Prevent Crash.
I = (Index *) malloc(sizeof(Index) * m * n); //Check Mem Allocation To Prevent Crash.
while ( c < Size ) { for ( i = Start; i < n; i++,c++) { I[c].m = Start; I[c].n = i; } for ( i = Start+1; i < m; i++,c++) { I[c].m = i; I[c].n = n-1; } for ( i = n-2; i >= Start; i--,c++) { I[c].m = m-1; I[c].n = i; } for ( i = m-2; i >= Start+1; i--,c++) { I[c].m = i; I[c].n = Start; }
m --; n --; Start++;
if ( m-1 == Start ) { if ( m > n ) for ( i = Start; i < n; i++,c++) { I[c].m = Start; I[c].n = n - Start; } if ( n < m ) for ( i = Start; i < m; i++,c++) { I[c].m = Start; I[c].n = n - Start; } } }
i = 0; for ( m = 0; m < p ; m++,printf("n")) for ( n = 0; n < q ; n++) Spiral [I[i].m] [I[i].n] = Linear[i++];
for ( m = 0; m < p ; m++,printf("n")) for ( n = 0; n < q ; n++) printf("%dt",Spiral[m][n]); return 0; }
/*~~~~~~~~~ Creates square and rectangular matrices ~~~~~~~~*/ /* Input required is dim of the spiral matrix. Just feed in two factors of the size of array. i.e If Items are 35 then m = 5 n = 7 or m = 7 n = 5 or m = 35 n = 1 or m = 1 n = 35. If Items are 36 then m = 1/3/4/6/9/12/36 n = 36/12/9/6/4/3/1 */
typedef struct { int m,n; }Index;
int Create_Spiral_Matrix ( int Linear[],int Size ) { int **Spiral; int m = 0 ,n = 0, p = m , q = n, i; int c = 0, Start = 0; Index *I;
while ( m*n != Size ) { printf("nFeed in the dimensions of the Spiral Matrix to be formed := "); scanf("%d %d",&m,&n); } p = m; q = n;
Spiral = (int **) malloc( m * sizeof(int *)); //Check Mem Allocation To Prevent Crash. for ( i = 0; i < m; i++) Spiral[i] = (int *) malloc( n * sizeof(int)); //Check Mem Allocation To Prevent Crash.
I = (Index *) malloc(sizeof(Index) * m * n); //Check Mem Allocation To Prevent Crash.
while ( c < Size ) { for ( i = Start; i < n; i++,c++) { I[c].m = Start; I[c].n = i; } for ( i = Start+1; i < m; i++,c++) { I[c].m = i; I[c].n = n-1; } for ( i = n-2; i >= Start; i--,c++) { I[c].m = m-1; I[c].n = i; } for ( i = m-2; i >= Start+1; i--,c++) { I[c].m = i; I[c].n = Start; }
m --; n --; Start++;
if ( m-1 == Start ) { if ( m > n ) for ( i = Start; i < n; i++,c++) { I[c].m = Start; I[c].n = n - Start; } if ( n < m ) for ( i = Start; i < m; i++,c++) { I[c].m = Start; I[c].n = n - Start; } } }
i = 0; for ( m = 0; m < p ; m++,printf("n")) for ( n = 0; n < q ; n++) Spiral [I[i].m] [I[i].n] = Linear[i++];
for ( m = 0; m < p ; m++,printf("n")) for ( n = 0; n < q ; n++) printf("%dt",Spiral[m][n]); return 0; }
Latest Answer : /*~~~~~~~~~ Creates square and rectangular matrices ~~~~~~~~*//* Input required is dim of the spiral matrix. Just feed in two factors of the size of array. i.e If Items are 35 then m = 5 n = 7 or m = 7 n = 5 or m = 35 n = 1 or m = 1 n = 35. ...
Write a program to read a four digit integer and print the sum of its digits.Write a program that reads a floating point number and then displays the right-most digit of the integral part of the number.
Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
The steps involved in building a C program are:
1. First program is created by using any text editor and the file is stored with extension as .c
2. Next the program is compiled. There are many compilers available like GNU C compiler called as gcc, Sun compiler, Borland compiler which is pop
SQL Programming Overview
Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s al
How to turn someone else’s mistake to your advantage
Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
IT Certification programs have several options that will offer you the best knowledge. By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.
IT Certification offers several vari
Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law