Answer Posted / om
#include<iostream>
using namespace std;
//----------------------
void spiral_way(int Row_size,int Column_size,int a[][4])
{
int
i,j,d=0,Current_row_size=Row_size,Current_column_size=Column_size,
Counter=Row_size*Column_size;
while(Counter>0) //Initailly my "Counter" is set to
total no. of elemnet in my 2-D array. so now I will
decrement it as I cover a element.
{
i=d;j=d;
while(j<Current_column_size-1) {
printf("%d\t",a[i][j]); j++; Counter--;}
//this is for printing the first row in forward direction.
while(i<Current_row_size-1) {
printf("%d\t",a[i][j]); i++; Counter--;}
//this is for printing the last cloumn in downward direction.
while(j>d) {
printf("%d\t",a[i][j]); j--; Counter--; }
//this is for printing the last row in backward direction.
while(i>d) {
printf("%d\t",a[i][j]); i--; Counter--; }
//this is for printing the first column in upward direction.
//When I completed the outer rectangle I move in to inner
rectangle by incrementing "d".
//and decrementing the "Current_row_size" and
"Current_column_size".
d++;
Current_row_size--;
Current_column_size--;
}
}
//-------------------------
int main()
{
int a[5][4]={{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16},
{17,18,19,20}
};
spiral_way(5,4,a);
//system("pause");
return 0;
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Write a program to find factorial of a number using recursive function.
What is file in c language?
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
main() { printf("hello"); fork(); }
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
What is the use of header files?
Why doesnt that code work?
What is the argument of a function in c?
What would be an example of a structure analogous to structure c?
Write a program to print factorial of given number without using recursion?
Between macros and functions,which is better to use and why?
What is the use of linkage in c language?
Write a factorial program using C.
Can we change the value of constant variable in c?
What is oops c?