-
j = M;
-
do
-
{
-
i = 0;
-
do
-
{
-
sum5 = sum5 + array[i][j];
-
i++;
-
}while(i < N);
-
j++;
-
}while(j == M);
-
So, M and N are both defined at 5. This piece of code is meant to add together a row from an array declared before, but fails to get the answer right.
The answer is 22 + 62 + 54 + 25 + 48 = 211, yet this program calculates it to 168. Below is the array declared before, the do... while cycles are the same for the other four lines, yet this one comes up short.
{
{98, 14, 99, 49, 22},
{89, 64, 84, 73, 62},
{97, 56, 37, 97, 54},
{84, 32, 93, 15, 25},
{85, 50, 58, 18, 48}
};
1 1109
There are bugs in the code.
j is 5.
The first loop is entered with j of 5 and i of 0. Then element sum[0][5] is accessed. This is outside the array so results are indeterminate.
After the first loop j, which is still 5 is incremented so it's now 6. The outer loop won't exit until j equals M and 6 will never equal 5. This looks like an infinite loop.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Justin Hoffman |
last post by:
This is a question concerning query optimisation. Sorry if it's a bit long,
but thanks to anyone who has the patience to help - This is my first post
here...
If I have two tables: 'tblContact' and 'tblCategory' where categories are
like:
Code Name
010101 Short
010102 Fat
|
by: Nigel Molesworth |
last post by:
I've Googled, but can't find what I need, perhaps I asking the wrong
question!
I want a "FAQ" page on a web site, I hate those pages that scroll you to
the answer so and I figured that a good way to do it would be to have
hidden content under each question, something like this :
What is the first letter of the alphabet?
|
by: Glen Herrmannsfeldt |
last post by:
I was compiling a program written by someone else about six years ago, and
widely distributed at the time. It also includes makefiles for many
different systems, so I know it has been compiled with many different
compilers.
I got compile errors when it used va_arg to fetch an argument of type short.
That seemed a little strange to me, so I...
|
by: NilsNilsson |
last post by:
I wrote this:
short s1 = 0;
short s2 = 1;
short s3 = s1 + s2;
And gor this compile error message: Cannot implicitly convert type 'int' to
'short'
What is wrong here?
|
by: iFriend |
last post by:
Hello!
I'm absolutely new here. Thank you for this forum.
I have the following question:
What would be a C# code to slow down the CPU for a planned interval, so that the CPU consumes less power in that time?
Any ideas?
Thank you all in advance!
| |
by: CptDondo |
last post by:
I'm trying to write what should be a simple program, and it keeps
hanging if I use volatile....
The program, stripped of its error checking, is this:
unsigned short * start;
unsigned short * ctl;
int fd = open("/dev/mem", O_RDWR);
start = mmap(0, getpagesize()*2, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
|
by: theinvisibleGhost |
last post by:
Is there a method of determining which format the short date format is
stored in for the current user on the machine using .NET?
If it is not in UK format I ideally need to be able to set it to UK
format as well.
I'm building an installation tool, and the software which I am
installing will
only work if the regional settings are correct.
|
by: =?Utf-8?B?TWlrZTE5NDI=?= |
last post by:
This is an example that is supposed to work in VB
http://support.microsoft.com/kb/175512/en-us
After spending a couple of hours downloading and installing VB Express 2008
after someone told me it was easy, the thing doesn't work any better.
These two instruction lines are not functional
3. Place a Common Dialog control on the form.
4. From...
|
by: Gernot Frisch |
last post by:
Hi,
the program below workes w/o problems on a GP2X and on the PC, but my
PocketPC (using GCC 3.3.3) crashes.
Very dissapointing, since I expect some speed boost from it.
Thnak you for your help.
int dx=..; // number of pixels width to draw
// one pixel is one unsigned short
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |