Question: Problem: Convert a C program to a Goto-C program. Read the following for information on how Goto-C works and for examples: Goto-C refers to a
Problem: Convert a C program to a "Goto-C" program.
Read the following for information on how "Goto-C" works and for examples:
"Goto-C refers to a programming language that is C with the following modifications: The only kind of if statement allowed in Goto-C is the following: if (expression) goto label ; Goto-C does not have the following keywords and operators: else while for do switch && || Goto-C does not have ?: the conditional operator.




MAKE SURE TO TRANSLATE ANY EXPRESSIONS THAT USE else, for, while, do, switch &&, ||. THESE ARE ILLEGAL KEYWORDS AND MUST BE REMOVED. CONFIRM THAT THE ORGINAL C CODE AND "Go-to C" CODE PRODUCE THE SAME OUTPUT! PLEASE PROVIDE THE "Go-to C" CODE AND SCREENSHOTS OF THE OUTPUTS.
The original c file is provided below
// lab1exH.c
#include
void print_array(const char *str, const int *a, int n);
// Prints the string given by str on stdout, then
// prints a[0], a[1], ..., a[n - 1] on stdout on a single line.
void sort_array(int *x, int n);
// Sorts x[0], x[1], ..., x[n - 1] from smallest to largest.
int main(void)
{
int test_array[] = { 4000, 5000, 7000, 1000, 3000, 4000, 2000, 6000 };
print_array("before sorting ...", test_array, 8);
sort_array(test_array, 8);
print_array("after sorting ...", test_array, 8);
return 0;
}
void print_array(const char *str, const int *a, int n)
{
int i;
puts(str);
for (i = 0; i
printf(" %d", a[i]);
printf(" ");
}
void sort_array(int *x, int n)
{
// This is an implementation of an algorithm called selection sort.
int outer, i, i_min, temp;
for (outer = 0; outer
i_min = n - 1;
for (i = n - 2; i >= outer; i--)
if (x[i]
i_min = i;
temp = x[outer];
x[outer] = x[i_min];
x[i_min] = temp;
}
}
Consider the following simple fragment of normal C: if (x >= 0) y = x; else y = -x; The above is illegal in Goto-C for two reasons: the if statement is not in an acceptable form, and the banned keyword else is used. One way to translate the fragment to Goto-C is as follows: if (x = 0){ printf("%d ", i); i--; } can be written as: loop-top: if (i 0 && x / y >- 10) { foo(x); bar(y); } can be coded as if (y
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
