By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

problem with my code.....

P: n/a
here is my code written below but i could figure out howmany times the
assignment statement at Line 21 execute when my code run?
13 void f1(int a[]) {
14 int x, y;
15 int t;
16 for(x = 1; x < 10; x++) {
17 if(a[x] = a[x - 1]) {
18 t = a[x];
19 y = x;
20 do {
21 a[y] = a[y - 1];
22 y--;
23 } while (y 0 && a[y - 1] t);
24 a[y] = t;
25 }
26 }
27 return;
28 }
29 int main (int argc, char **argv)
30 {
31 int a[10];
32 char reply;
33 for (int i = 0; i < 10; i++) a[i] = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a[i] << endl;

Mar 22 '07 #1
Share this Question
Share on Google+
12 Replies


P: n/a
ia*************@gmail.com wrote:
here is my code written below but i could figure out howmany times the
assignment statement at Line 21 execute when my code run?
Add a counter.
>
13 void f1(int a[]) {
14 int x, y;
15 int t;
16 for(x = 1; x < 10; x++) {
17 if(a[x] = a[x - 1]) {
18 t = a[x];
19 y = x;
20 do {
21 a[y] = a[y - 1];
22 y--;
23 } while (y 0 && a[y - 1] t);
24 a[y] = t;
25 }
26 }
27 return;
28 }
29 int main (int argc, char **argv)
30 {
31 int a[10];
32 char reply;
33 for (int i = 0; i < 10; i++) a[i] = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a[i] << endl;

--
Ian Collins.
Mar 22 '07 #2

P: n/a
On Mar 22, 4:00 pm, Ian Collins <ian-n...@hotmail.comwrote:
ianenis.tiry...@gmail.com wrote:
here is my code written below but i could figure out howmany times the
assignment statement at Line 21 execute when my code run?

Add a counter.
13 void f1(int a[]) {
14 int x, y;
15 int t;
16 for(x = 1; x < 10; x++) {
17 if(a[x] = a[x - 1]) {
18 t = a[x];
19 y = x;
20 do {
21 a[y] = a[y - 1];
22 y--;
23 } while (y 0 && a[y - 1] t);
24 a[y] = t;
25 }
26 }
27 return;
28 }
29 int main (int argc, char **argv)
30 {
31 int a[10];
32 char reply;
33 for (int i = 0; i < 10; i++) a[i] = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a[i] << endl;

--
Ian Collins.- Hide quoted text -

- Show quoted text -
i didnt understand what does that mean Ian Collins? please it is
urgent i need to ork on this assignment and turn it in... help me!!!!

Mar 22 '07 #3

P: n/a
ia*************@gmail.com wrote:
On Mar 22, 4:00 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>ianenis.tiry...@gmail.com wrote:
>>>here is my code written below but i could figure out howmany times the
assignment statement at Line 21 execute when my code run?

Add a counter.
*Please* don't quote signatures.
>

i didnt understand what does that mean Ian Collins? please it is
urgent i need to ork on this assignment and turn it in... help me!!!!
A variable to count the number of times the line is executed.

Don't leave your homework to the last moment!

--
Ian Collins.
Mar 22 '07 #4

P: n/a
i am still confused....????

Mar 22 '07 #5

P: n/a
de********@gmail.com wrote:
i am still confused....????
About what?

--
Ian Collins.
Mar 22 '07 #6

P: n/a
so this guy supposed to add a variable to be able to count stuff or
what...?? i am trying to learn C++ too and this is kind of interesting
if anyone can answer my question i would appreciate..

Mar 22 '07 #7

P: n/a
de********@gmail.com wrote:
so this guy supposed to add a variable to be able to count stuff or
what...?? i am trying to learn C++ too and this is kind of interesting
if anyone can answer my question i would appreciate..
What question?

Please quote some context, this post does not make any sense on its own.

--
Ian Collins.
Mar 22 '07 #8

P: n/a

as far as i understand his question, they ask him to find a way to
figure out how many times one line executes when you run the code.
What i am saying is is there any predefined function or something like
that you can use to figure it out or what else you can do?

Mar 22 '07 #9

P: n/a
de********@gmail.com wrote:
as far as i understand his question, they ask him to find a way to
figure out how many times one line executes when you run the code.
What i am saying is is there any predefined function or something like
that you can use to figure it out or what else you can do?
No.

That's why I suggested adding a counter variable to the code that can be
incremented on each assignment. Computers are better at counting than
people.

--
Ian Collins.
Mar 22 '07 #10

P: n/a
On Mar 23, 7:58 am, ianenis.tiry...@gmail.com wrote:
here is my code written below but i could figure out howmany times the
assignment statement at Line 21 execute when my code run?

13 void f1(int a[]) {
14 int x, y;
15 int t;
16 for(x = 1; x < 10; x++) {
17 if(a[x] = a[x - 1]) {
Seems this condition will execute always. Did you intend
comparison("==") instead of assigment("=")?

Regards,
Sarath
http://sarathc.wordpress.com/

Mar 23 '07 #11

P: n/a
<de********@gmail.comwrote in message
news:11**********************@p15g2000hsd.googlegr oups.com...
>
as far as i understand his question, they ask him to find a way to
figure out how many times one line executes when you run the code.
What i am saying is is there any predefined function or something like
that you can use to figure it out or what else you can do?
The orignal question was obvoiusly homework and it is the custom of this
group to only give points to homework, not do their assignments for them.
Also, you should always quote from the message you are replying to, as I
have here.

A counter is just a variable that gets incremented.

int a = 0;

do (whilesomethingistrue)
{
++a;
// do some stuff
};

std::cout << "Number of times exectued: " << a << "\n':

Understand?
Mar 23 '07 #12

P: n/a
Sarath wrote:
:: On Mar 23, 7:58 am, ianenis.tiry...@gmail.com wrote:
::: here is my code written below but i could figure out howmany times
::: the assignment statement at Line 21 execute when my code run?
:::
::: 13 void f1(int a[]) {
::: 14 int x, y;
::: 15 int t;
::: 16 for(x = 1; x < 10; x++) {
::: 17 if(a[x] = a[x - 1]) {
::
:: Seems this condition will execute always. Did you intend
:: comparison("==") instead of assigment("=")?
::

Possibly. But it will not execute if the assigned value is zero (and thus
convertible to false).

I thought that was part of the original difficulties - the execution is
controlled by the actual data. .-)

Bo Persson
Mar 24 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.