Question

1. Identify and correct the errors in each of the following statements: a) for (a =...

1. Identify and correct the errors in each of the following statements:

a)

for (a = 25, a <= 1, a--); {printf("%d\n", a);}

b) The following code should print whether a given integer is odd or even:

switch (value) {case (value % 2 == 0):puts("Even integer");case (value % 2 != 0):puts("Odd integer");}

c) The following code should calculate incremented salary after 10 years:

for (int year = 1; year <= 10; ++year) {double salary += salary * 0.05;}printf("%4u%21.2f\n", year, salary);

d)

for (double y = 7.11; y != 7.20; y += .01)printf("%7.2f\n", y);e) The following code should output all multiples of 3 from 1 to 100:for (int x = 3; x <= 100; x%3 == 0; x++ ) {printf("%d\n", x);}

e) The following code should output all multiples of 3 from 1 to 100:

for (int x = 3; x <= 100; x%3 == 0; x++ ) {printf("%d\n", x);}

Homework Answers

Answer #1

Answer a:
the loop will never execute as the condition is false
corrected Code:
for (a = 25, a >= 1, a--); {printf("%d\n", a);}

Answer b:
switch (value%2) {
case 0:
   puts("Even integer");
   break;
case 1:
   puts("Odd integer");}
   break;
}

Answer c:
double salary=1000;
for (int year = 1; year <= 10; ++year) {
   salary+= salary * 0.05;
}
printf("%4u%21.2f\n", year, salary);

Answer d:
for (int x = 3; x <= 100; x+=3 ) {
   printf("%d\n", x);
}
Answer e:
for (int x = 3; x <= 100; x+=3 ) {
   printf("%d\n", x);
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
#include <stdio.h> #pragma warning(disable : 4996) // CSE 240 Fall 2016 Homework 2 Question 3 (25...
#include <stdio.h> #pragma warning(disable : 4996) // CSE 240 Fall 2016 Homework 2 Question 3 (25 points) // Note: You may notice some warnings for variables when you compile in GCC, that is okay. #define macro_1(x) ((x > 0) ? x : 0) #define macro_2(a, b) (3*a - 3*b*b + 4*a * b - a*b * 10) int function_1(int a, int b) { return (3*a - 3*b*b + 4*a * b - a*b * 10); } // Part 1: //...
Given the following code: int x = 0; int y = 10; int *ptr = &x;...
Given the following code: int x = 0; int y = 10; int *ptr = &x; *ptr = -55; x += -52; ptr = &y; *ptr += 52; printf("%d\n", x); What is printed to the screen?
c++ language material Choose the correct answer please 1-When allocate memory with size 64 byte :...
c++ language material Choose the correct answer please 1-When allocate memory with size 64 byte : Int *m=new int [31]; Float *m=new float[8]; Double *m=new double[8]; Long *m=new long[16] 2-When print the address of the fifth character in pointer n on the screen : Printf("%p", n[4]); Printf("%p", n+5); Printf("%p",&n[4]); Printf("%p",n[5]); 3-to see the moving of a circle (circle(x,y,10)) from left top corner to right lower corner on the screen we need to ___________________ increase x and decrease y increase x...
(5 pts.) Consider the C program below. Recall that fflush() just forces the printed value to...
(5 pts.) Consider the C program below. Recall that fflush() just forces the printed value to be output immediately. (For space reasons, we are not checking error return codes, so assume that all functions return normally.) int main () {    if (fork() == 0) {        if (fork() == 0) {           printf("3"); fflush(stdout);        }        else {           pid_t pid; int status;           if ((pid = wait(&status)) > 0) {                  printf("4"); fflush(stdout);           }        }...
IN C++ VERY EASY What's wrong with this code? The following function prints a reverse half-pyramid...
IN C++ VERY EASY What's wrong with this code? The following function prints a reverse half-pyramid populated by the alternating dots and stars (see example below). The odd rows contain stars and even rows contain dots. Debug the code to fix all the compilation and run-time errors, so that the code generates the desired output. For instance, when the 'n' value passed to the function is 6, the output would look like the following. ****** ..... **** ... ** ....
I am trying to write a program in C language but keep running into errors. Any...
I am trying to write a program in C language but keep running into errors. Any help would be awesome. here is my code I have so far. #include <stdio.h> #include <conio.h> #include <string.h> int main(){    int lenght, i = 0, state = 0;    char line[100];    printf("enter the string for checking of comment line: \n");    gets(line);    while(i < strline(line)){        switch(state){            case 0: if (line[i] == '/'){               ...
You’re the grader. To each “Proof”, assign one of the following grades: • A (correct), if...
You’re the grader. To each “Proof”, assign one of the following grades: • A (correct), if the claim and proof are correct, even if the proof is not the simplest, or the proof you would have given. • C (partially correct), if the claim is correct and the proof is largely a correct claim, but contains one or two incorrect statements or justications. • F (failure), if the claim is incorrect, the main idea of the proof is incorrect, or...
(4) 1. Simplify the following assignments/calculations if possible: a. a = 0; b = 0; c...
(4) 1. Simplify the following assignments/calculations if possible: a. a = 0; b = 0; c = 0; d = 0; _____________________________ b. n1 = n1 % n2; _____________________________ c. n3 += 1; _____________________________ d. n4 = n5 / n4; _____________________________ 2. Suppose that the statement x = 12; has already been done. What values will the following printf statements output assuming that the statements are done in the following order: a. printf("%d\n", ++x); __________ b. printf("%d\n", x); __________ c....
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 extern char **environ;    5 void output(char *a[], char...
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 extern char **environ;    5 void output(char *a[], char *b[]) { 6 int c = atoi(a[0]); 7 for (int i = 0; i < c && b[i]; ++i) { 8 printf("%s", b[i]+2); 9 } 10 } 11 12 void main(int argc, char *argv[]) { 13      14 switch (argc) { 15 case 1: 16 for (int i = 0; environ[i]; ++i) {    17 printf("%s\n", environ[i]); 18 } 19 break; 20 default: 21 output(argv +...
Please find the errors of the following code a) int x[5]; int k = 10; for...
Please find the errors of the following code a) int x[5]; int k = 10; for (k = 0; k <= 5; k++) { x[k] = k -1; } b) int x[5]; for (k = 1; k <= 5; k++) { cout << x[k-1] << endl; } c) int x[5]={1,2,3,4,5}, y[5]; y = x; for (k = 0; k < 5; k++) { cout << y[k] << endl; } d) int size; cin >> size; int myArr[size];