Question

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);}

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);

}

#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:
//...

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 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);
}
}...

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] == '/'){
...

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.
******
.....
****
...
**
....

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 = 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....

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];

3. Identify the hypothesis and conclusion in the following
statements. Then, find a counter example showing that the statement
is false. Here n, m, and p are originally assumed to be
integers.
Statement 1. If m and n are integers, then
m/n is an integer.
Statement 2. If m and n are
positive integers, then m - n is a positive
integer.
Statement 3. If p is an odd prime number, then
p^2 + 2 is a prime number.
Statement...

There are 7 syntax errors and 3 semantic errors in the following
code segment. Please mark them in the code and explain the reason
briefly in place.
#include<iostream>
using namespace std;
int main()
{
cout<<”Please input the radius (in integer):
”>>endl;
int 1var = 10, var=20;
double area = 40;
cin<< var; //get an input of the radius and store in
var
float continue;
float const pi = 2.64;
pi += 0.5;
do
{
cout<<”The radius is ”<<”var”<<endl; //print
the...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 7 minutes ago

asked 9 minutes ago

asked 15 minutes ago

asked 27 minutes ago

asked 38 minutes ago

asked 38 minutes ago

asked 52 minutes ago

asked 56 minutes ago

asked 58 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago