|
hi guys,
this program creates number spiral Matrix
For example :
Enter a number : 4
01 02 03 04
12 13 14 05
11 16 15 06
10 09 08 07
Code :
#include <iostream.h>
int main()
{
int UserNo=1; // default Value
int StoreArray[100][100];
cout<<endl<<"Please enter a number :";
cin>>UserNo;
int Sqr=UserNo*UserNo;
int r=1,c=UserNo;
StoreArray[UserNo][UserNo];
int n=1;
do
{
for (int b=r;b<=c;b++)
{
StoreArray[r][b]=n;
n++;
}
for (b=r+1;b<=c;b++)
{
StoreArray[b][c]=n;
n++;
}
n--;
for (b=c;b>=r;b--)
{
StoreArray[c][b]=n;
n++;
}
for (b=c-1;b>=r+1;b--)
{
StoreArray[b][r]=n;
n++;
}
r++;
c--;
}while (n<sqr);>
if (UserNo%2!=0)
{
int mid=((UserNo/2) +1);
StoreArray[mid][mid]=Sqr;
}
// DISPLAYING
for (int a=1;a<=UserNo;a++)
{
for (int b=1;b<=UserNo;b++)
{
cout<<StoreArray[a][b]<<" | ";
}
cout<<endl;
}
return 1;
}
|
|
|
|
|
AnkurS wrote: this program creates number spiral Matrix
Thanks for your effort!
Maxwell Chen
|
|
|
|
|
And... ? What is the question ?
|
|
|
|
|
Cedric Moonen wrote: And... ? What is the question ?
OP don't want to ask any questions, perhaps instead of posting an article he posted a message.
"Life was much simpler in 2002"
|
|
|
|
|
hi,
The following one shows hello world.
#include <stdio.h>
void main()
{
printf("hello world\n");
}
</stdio.h>
Greetings.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: hello world
It reminds me the article "Evolution of a programmer".
Maxwell Chen
|
|
|
|
|
|
I see some MFC macro use do{}while(0), for example
#define AfxOutputDebugString(lpsz) \<br />
do \<br />
{ \<br />
USES_CONVERSION; \<br />
_RPT0(_CRT_WARN, W2CA(lpsz)); \<br />
} while (0)<br />
#else
why use this kind of technique?
|
|
|
|
|
Not anymore! Now AfxOutputDebugstring is defined as:
#define AfxOutputDebugString TRACE
Maxwell Chen
|
|
|
|
|
Hi,
the do{} while(0) is a technique to force the programmer to place a ; after the MACRO line so it looks more like a normal function then a macro
codito ergo sum
|
|
|
|
|
|
Hi, I'm currently using Borland C++ Builder 6.0 right, and since I'm still a beginner in using this tool, I find many difficulties in using this tool...
I wanted to make multiple forms that could communicate with each other, but I still can't make it...
It's probably a silly question, but I'm trying to get the input from the pop-up window and display it at the main window... But I still can't figure the right way to do it... I wrote the program like the following (Note : Form1 is the main window, and Form2 is the pop-up window)
Where, form1 has 2 button, which is btnInput(to show the pop-up window) and btnClose (to close the application), meanwhile form2 has 2 button, which is btnOK (to retrieve the input and close the pop-up window) and btnCancel (just close the pop-up window)
//---------------------------------------------------------------------------
#include <vcl.h>;
#pragma hdrstop
#include "Main.h"
#include "PopUp.cpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TForm2 *Form2;
String input;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnInputClick(TObject *Sender)
{
Form2->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnCloseClick(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::btnOKClick(TObject *Sender)
{
input = Form2->Edit1->Text;
Form1->lblInput->Caption = input;
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::btnCancelClick(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
Is there anyone who could help, pleaseee...
|
|
|
|
|
|
Hello all
I want to develop application to communicate my pc and my office pc.
In this application, on My office PC i have made one application for listening on Socket for connection.
Now how can i develop an application for my home PC so that i con connect to my office PC?
One think i see on internet is that it is possible with VPN, But its to hard process.
So i want to know any other alternative for it.
Is there anybody who can solve my Problem?
Thanks in advance.
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
Hello everyone,
I am looking for a good sample about how to implement C++ pre-condition and post condition check, but can not find a good sample code. Do you have any referred ones?
Since I can not find, I wrote the patterns in two ways, I am not sure which is correct and if both are not correct, how to implement this pattern?
Sample code 1,
#define MAX 1024
class Base
{
public:
void foo(int i)
{
if (i > MAX)
{
}
else
{
do_foo(i);
}
}
private:
virtual void do_foo(int i) = 0;
};
class Derived : public Base
{
private:
virtual void do_foo(int i)
{
}
};
int main()
{
Derived d;
d.foo (1000);
return 0;
}
Sample 2,
#define MAX 1024
class Base
{
public:
void foo(int i)
{
if (i > MAX)
{
}
else
{
do_foo(i);
}
}
private:
virtual void do_foo(int i) = 0;
};
class Derived : public Base
{
public:
virtual void do_foo(int i)
{
foo (i);
}
};
int main()
{
Derived d;
d.do_foo (1000);
return 0;
}
thanks in advance,
George
|
|
|
|
|
A word of advice not related to your problem: dump the macros! Use an enum instead, for example. One disadvantge of using macros is that they don't have scope and so can't be put into namespace and such.
enum { MAX = 1024 };
Steve
modified on Monday, March 17, 2008 1:49 AM
|
|
|
|
|
Thanks Steve,
My bad, any comments or replies to my original question?
regards,
George
|
|
|
|
|
I prefer the first; why make do_foo public ? This seems to go against the pattern being used.
Steve
|
|
|
|
|
Thanks Steve,
1.
Stephen Hewitt wrote: against the pattern
You mean template method pattern? or something which hides implementation details?
2.
Do you have some more formal examples about pre and post condition implementation in C++? The samples I wrote are by myself. I want to learn some formal ones.
regards,
George
|
|
|
|
|
|
Thanks Steve,
I do not think it contains a sample of pre and post conditions and it only mentions the term pre and post condition check. I have read this article before.
If I am wrong, please feel free to correct me and point out the sample you refer in this article.
regards,
George
|
|
|
|
|
The pre and post checks would obviously be specific to the function and the interface "contract".
Steve
|
|
|
|
|
Thanks Steve,
My question is more about the pattern of pre- and post- condition check. Not about how to do a specific implementation. I have performend some search, but failed to find any definition.
Any recommended resources?
regards,
George
|
|
|
|
|
It is not public. Or did he just cheat changing it without notice?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
It's public in class Derived in the second example.
Steve
|
|
|
|