Question

In: Computer Science

C PROGRAMMING Identify and correct the errors in each of the following. [Note: There may be...

C PROGRAMMING

Identify and correct the errors in each of the following. [Note: There may be more than one

error in each piece of code.]

a)

if ( sales => 5000 )

puts( "Sales are greater than or equal to $5000" )

else

puts( "Sales are less than $5000 )

b)

int x = 1, product = 0;

while ( x <= 10 ); {

product *= x;

++x;

}

c)

While ( x <= 100 )

total =+ x;
++x;

d)

while ( y < 10 ) {

printf( "%d\n", y );

}

Solutions

Expert Solution

// Note: Below are the corrected statement with incorrection marked after // for eg ; is missing

Ans a)

   if ( sales >= 5000 ) // correct way is >=
       puts( "Sales are greater than or equal to $5000" ); // semicolon missing
   else
       puts( "Sales are less than $5000 "); // " and ; missing

---------

Ans b)

Note: In this code there is one syntax error in while loop there is also one logic error product should be equal to 1 inorder to do product 1 to 10

   int x = 1, product = 1;
   while ( x <= 10 ) { // no need of semicolon
       product *= x;
       ++x;
   }

---------------

Ans c)

while ( x <= 100 ){ // curly braces and W should be small
       total =+ x;
       ++x;
   }

-------------

Ans d)

   while ( y < 10 ) {
       printf( "%d\n", y );
       y++; // y should be incremented
   }


Related Solutions

Identify and correct the errors in each of the following statements: a) printf( "The value is...
Identify and correct the errors in each of the following statements: a) printf( "The value is %d\n", &number ); b) scanf( "%d%d", &number1, number2 ); c) if ( c < 7 );{ printf( "C is less than 7\n" ); } d) if ( c => 7 ) { printf( "C is greater than or equal to 7\n" );
There are two errors in this code. Identify the errors and give the correct code that...
There are two errors in this code. Identify the errors and give the correct code that will make the program to display the following output: Rectangle: height 2.0 width 4.0 Area of the Rectangle is 8.0 ----- public interface Shape { public double getArea(); } class Rectangle implements Shape { double height; double width; public Rectangle(double height, double width) { this.height=height; this.width=width; } public double getArea() { return height*width; } public String toString() { return "Rectangle: height "+height+" width "+width;...
Find and correct at least two errors in each of the following segments of code. a)...
Find and correct at least two errors in each of the following segments of code. a) final int ARRAY_SIZE = 5; ARRAY_SIZE = 10; int[] table = new int[ARRAY_SIZE]; for (int x = 0; x <= ARRAY_SIZE; x++) table[x] = 99; b) String[] names = {“Mina” , “George”}; int totalLength = 0; for (int i = 0; i <= names.length() ; i++) totalLength += names[i].length; c) String[] words = “Hello”,“Goodbye”; System.out.println(words.toUpperCase()); d) public class MyClass { private int x; private...
Which of the following statements are TRUE? Note that there may be more than one correct...
Which of the following statements are TRUE? Note that there may be more than one correct answer; select all that are true. There are countably infinite values of X in a continuous uniform distribution. For a continuous uniform distribution defined on the interval [a,b], P(X < a) and P(X > b) is undefined. The mean and the variance of a continuous uniform random variable are the same. In a continuous uniform distribution, the mean and the median are the same....
Identify errors and correct them of the following Java program : 1. import java.utility.Random; 2. 3....
Identify errors and correct them of the following Java program : 1. import java.utility.Random; 2. 3. public class Sequen 4. 5. private int stand 6. private int calc; 7. 8. public Sequen(int numStand) 9. { 10. stand = numStand; 11. skip; 12. } 13. 14. public void skip() 15. { 16. Random sit = new Random(); 17. calc = sit.nextInt(stand) + 1; 18. } 19. 20. public getStand() 21. { 22. return stand; 23. } 24. 25. int getCalc() 26....
The following question must be answered in the C programming language and may not be written...
The following question must be answered in the C programming language and may not be written in C++ or any other variation. Problem 5 This problem is designed to make sure you can write a program that swaps data passed into it such that the caller's data has been swapped. This is something that is done very frequently in manipulating Data Structures. The Solution / Test Requirements I want your program to demonstrate that you understand how to swap information...
The following code segment which uses pointers may contain logic and syntax errors. Find and correct...
The following code segment which uses pointers may contain logic and syntax errors. Find and correct them. a) Returns the sum of all the elements in summands int sum(int* values) { int sum = 0; for (int i = 0; i < sizeof(values); i++) sum += *(values + i); return sum; } b) Overwrites an input string src with "61C is awesome!" if there's room. Does nothing if there is not. Assume that length correctly represents the length of src....
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } Identify 5 other errors and give their Line Number, Error...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } One error is already identified for you as shown below:...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } One error is already identified for you as shown below:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT