Consider the following C program segment . Rewrite it using no gotos or breaks.
j = -3;
For (I = 0; I < 3; I++){
Switch ( j + 2) {
Case 3:
Case 2: j--; break;
Case 0: j +=; break;
Default: j = 0;
}
if ( j > 0) break;
j = 3 – I
}
Consider the following C program segment . Rewrite it using no gotos or breaks.
j = -3;
For (I = 0; I < 3; I++){
Switch ( j + 2) {
Case 3:
Case 2: j--; break;
Case 0: j +=; break;
Default: j = 0;
}
if ( j > 0) break;
j = 3 – I
}
Is this written in C?
Well the best way I think this works is:
My syntax may be wrong though.Code:int main() { int i, j; j = -3; for (i = 0; i < 3; i++){ if ((j + 2) == 2) { j--; }else if ((j + 2) == 0) { j++; }else { j = 0; } if (j < 0) j = 3 - i; } return 0; }
Last edited by Stack Overflow; 05-25-2004 at 10:37 PM.
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
thanx for the fast reply...
yes ... it is C.
First off, use code tags. Second off, stop having people do your work for you. Had you actually read the forum rules, you'd have known this. Don't try and disguise this as "well I just wanted to see if you could" either. Trust me, someone here, or more than one someones here can do just about anything you post. So take that as a given, read the forum guidelines, and don't try and disguise your homework or tests as "can anyone do this" BS.
Quzah.
Hope is the first step on the road to disappointment.
Oh,
:/ I thought he was asking syntatically since break and goto are cheap most of the time.
I'll have to keep on the look out for people like that
- Stack Overflow
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
Yeah, when you read this:Originally Posted by Stack Overflow
>Consider the following C program segment . Rewrite it using no gotos or breaks.
Well, you get the idea.