Question

The following program has some syntax errors. Enumerate the errors then rewrite, compile and run the...

The following program has some syntax errors. Enumerate the errors then rewrite, compile and run the program after correction.

#include <stdio.h>

int Main( );

{

float w ;

float wk ;

printf ("Enter your weight in pounds ");

scanf["%d" weight];   

wk=w x 0.45359237 ;

printf('Your weight in kilograms is %d',wk);

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Errors are as follows:

1.int Main( ) (should be main() )
2.scanf["%d" weight];   (weight is not defined. Most probably it should be w. Also '[' and ']' are not ok. ',' is missing. & should have been used, %f is more appropriate)
3.wk=w x 0.45359237 ; ( x should have been replaced by *)
4.printf('Your weight in kilograms is %d',wk); ( %f would have been more appropriate)

Following is the correct program:

#include <stdio.h>

int main()
{
float w;
float wk;
printf ("Enter your weight in pounds ");
scanf("%f", &w);
wk = w * 0.45359237;
printf("Your weight in kilograms is %f",wk);
}

Add a comment
Know the answer?
Add Answer to:
The following program has some syntax errors. Enumerate the errors then rewrite, compile and run the...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • help KKKL1164 4. The C program presented below has some syntax and logic errors. Analyse it...

    help KKKL1164 4. The C program presented below has some syntax and logic errors. Analyse it and highlight the errors, explaining how the errors can be corrected. This program attempts to solve a quadratic equation. #include <stdio.h> #include <math.h> int Main() const int a, b, Ci double doro, disc printf ("Lets find the root (s) of a printf ("ax 2 bx c. \n"); printf ("Please enter the coefficient a: scanf ("d", &c); printf ("Please enter the coefficient b: "); scanf...

  • 1- Correct the syntax errors in the following program, and rewrite the program so that it...

    1- Correct the syntax errors in the following program, and rewrite the program so that it follows the proper style conventions. What does the program do? (Write it out as a comment). (10 pts) #include <stdio.h> int main() {/* * Calculate and display the difference of two values *) int X, /* first input value */ x, /* second input value */ sum; /* sum of inputs */ X=9, x=7.5 X + x = sum; printf("%d + %d = %d\n";...

  • answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at...

    answer two question,each question has 3syntax errors,find it. 1(a) The following segment of code contains at least three (3) syntax errors that will compilation to fail with errors. Identify each of these errors and specify the solution. [2 marks each, 6 marks in total] cause #include <stdio.h> void main (void) float height; float area; printf "input height of the rectangle: ") scanf( "%f", &height) printf"input length of the rectangle: scanf"", &length); height length; area printf( area of rectangle %f high...

  • C program Classwork_3.3: Correct the program below that will read two numbers: number of drinks and...

    C program Classwork_3.3: Correct the program below that will read two numbers: number of drinks and number of sandwiches, and display the total bill calculated as: Total bill = Number of Drinks X 5.50 + Number of Sandwiches X 10.00 Answer the questions below. C-Program with error: Write the correct program here: #include<stdio.h> int main (void) floats numberofDrinks, numberofSandwiches; float totalBilling: printf("Enter number of Drinks \n"); scanf("%d",&numberofdrinks); printf("Enter number of Sandwiches\n") scanf("%f",&numberofSandwiches); totalbilling = numberofDrinks *5.50 + numberofsandwiches/10.00; printf("Total bill...

  • /* •   The following code consists of 5 parts. •   Find the errors for each part...

    /* •   The following code consists of 5 parts. •   Find the errors for each part and fix them. •   Explain the errors using comments on top of each part. */ #include <stdio.h> #include <string.h> int main( ) { ////////////////////////////////////////////////////////////////////////// //////////////        Part A. (5 points)                ////////////////// int g(void) { printf("%s", Inside function g\ n " ); int h(void) {       printf(" % s ", Inside function h\ n "); } } printf("Part A: \n "); g(); printf(" \n"); ////////////////////////////////////////////////////////////////////////// //////////////       ...

  • Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include...

    Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include <stdio.h> #define PI 3.14 typedef struct cylinder{    float r,h;    float areacircle=2*PI*r;    float areacylinder;    float volumecylinder;    areacylinder=2*PI*r*h+2*PI*r*r;    volumecylinder=PI*r*r*h; }; int main() {    float start,numcyls;    printf("How many cylinders do you want? Enter a positive integer.\n");    scanf("%f",&numcyls);    if(numcyls<1||ceilf(numcyls)!=numcyls)    while()    {printf("The number you have entered is not a positive integer. Please try again.\n");        printf("Remember,...

  • 1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf...

    1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf ("Hello!") return 0 2 Assume a program has the following declarations: short s- 4 int i--5; long m-3 float f-19.3f; double d-3.6; What are the following values? (a) s+m (b) (float) d (c) d s (e) (int) f 3 What will be the output of the following program: int x = 3 float a 2.76; y-2* x; print f("X-2d, y*ta, z»%d", x, y, z);...

  • The following program sorts the array of numbers entered by the user and prints out the...

    The following program sorts the array of numbers entered by the user and prints out the elements in descending order. It has many errors. Debug the code and show the output. #include <stdio.h> #define N 4 void desc(float *a, float *b) float tp; tp=a; a=b; b=tp; int main() int i, j, ii, mark[N] ; for (ii==0;ii<N;ii++) printf("Enter the %d th element of your array: \n",ii); scanf("%d", mark[ii]); printf("You have entered the following array: \n"); for (ii=0,ii<N,ii++) printf("%d ", mark[ii]); printf("\n...

  • C program. Using do-while loop for this question. Question: write a program to calculate the average...

    C program. Using do-while loop for this question. Question: write a program to calculate the average of first n numbers. output: Enter the value of n : 18 The sum of first 18 numbers =171 The average of first 18 numbers = 9.00 my code couldn't give me the right avg and sum. Please help. #include<stdio.h> int main() {     int num;     int count =0;     int sum=0;     float avg;      printf("Enter the value of n: ");    ...

  • Debug the following matrix program in C: // Program to read integers into a 3X3 matrix...

    Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) {         char size;         double Matrix[size][size+1];         printf("Enter 9 elements of the matrix:\n");         int i;         for (i = 0: i <= size: i++)     {       int j = 0;       for (; j <= size++; j++){         scanf("%d", matrix[i--][4])       }     }         Display(Matrix,9);         return 0; void...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT