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: //...
A program is already given to you.  There are five problems in this skeleton version of the...
A program is already given to you.  There are five problems in this skeleton version of the program, each is 10 points. All you got to do is complete the missing code in each function. What the function does is clearly stated in the name of the function.   // ASSIGNMENT ON FUNCTIONS #include <stdio.h> // Problem 1: Compile with gcc func_assignment.c -Wall // There are some warnings because there is a mismatch between // data type passed and defined. // Find...
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...
For each part labeled P(n), there is a warning/error/problem that goes with it. Write down what...
For each part labeled P(n), there is a warning/error/problem that goes with it. Write down what the issue was in the `Error:` section of each problem. And fix the code to make it work. // P0 #include <stdio.h> #include <stdlib.h> /* Error: */ void fib(int* A, int n); int main(int argc, char *argv[]) { int buf[10]; unsigned int i; char *str; char *printThisOne; char *word; int *integers; int foo; int *bar; char *someText; // P1 for (i = 0; i...
Why am I receiving different outputs when I run this code on visual studio and gcc...
Why am I receiving different outputs when I run this code on visual studio and gcc (unix)?. The correct output is -52. #define polyMacro(a, b) ((a * a) + (8 * a) + (3 * a * b) - (b * b)) int polyFunc(int a, int b) {    return ((a * a) + (8 * a) + (3 * a * b) - (b * b)); } int x = -7, y = 3; int x_copy = x, y_copy...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8 13 21 34 55 ....... and also need add code complexity time if you want! here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[ n + 1 ]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for ( i = 2; i < n; i++ ) { fib[ i ] = fib[ i -...
Consider the following variable definitions: char a, *b, *c; int d[2], *e; int i, *j; How...
Consider the following variable definitions: char a, *b, *c; int d[2], *e; int i, *j; How many total bytes does this code allocate for variables?  Assume a 32-bit representation for integer and pointer values. a     sizeof(char) b     sizeof(char *) c     sizeof(char *) d    2*sizeof(int) e     sizeof(int *) i     sizeof(int) j     sizeof(int *) Total number of bytes ? What is the output of the following piece of code? (Use the above variable definitions). j = &i; *j = 50;                      /* i = 50 */ e = &d[0]; *e...
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...
PLEASE EXPLAIN EACH LINE OF CODE ONLY. USE COMMENTS NEXT TO EACH LINE TO EXPLAIN WHAT...
PLEASE EXPLAIN EACH LINE OF CODE ONLY. USE COMMENTS NEXT TO EACH LINE TO EXPLAIN WHAT EACH IS CODE IS DOING THANKS. PLEASE COPY PASTE AFTER YOURE DONE NOT SCREENSHOT BECAUSE I NEED TO BE ABLE TO EDIT IT THANKS. // MODULE B: Method 2: Embedding an in-line asssembly language module in a C progrmming #include "stdafx.h" #include "stdio.h" #include<iostream> int main () { printf(" Lab_No_01_Getting_Stated_into_x86_Assembly_from_a_C++_program\n"); // Lab number and title here printf(" Module B: Embedding an in-line asssembly language...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT