6

Write a C program to calculate the area of the rectangle? Using the inputs from...

 2 years ago
source link: https://www.codeproject.com/Questions/5318832/Write-a-C-program-to-calculate-the-area-of-the-rec
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

See more:

the code is not running
the code is not working
how can i do it

What I have tried:
Copy Code
Copy Code
#include<stdio.h>

int main(){
    int length, breadth;
    printf("What is the length of the rectangle\n");
    scanf("%d", &length);

     printf("What is the breadth of the rectangle\n");
     scanf("%d", &breadth);

     printf("The area if your rectangle is %d", length*breadth);
    return 0;
}
Comments
Despite the similar names, C and C# are completely different languages. You have tagged your question as "C#", but the question title and code says you're using "C".
Quote:

the code is not running
the code is not working
how can i do it

If I copy'n'paste your code into an online C compiler (Online C Compiler - online editor[^]) it compiles cleanly, runs, and does exactly what I expect:
Copy Code
What is the length of the rectangle
21
What is the breadth of the rectangle
42
The area if your rectangle is 882

...Program finished with exit code 0
Press ENTER to exit console.

So the code does run, the code does work - I'd suggest that it's "finger trouble" at your end which obviously we can't see or help with: I'd suggest that you go back to yoru basic instructions on how to compile the code, and double check that to make sure it has been compiled correctly, linked correctly, and that there are no errors. Then check your instructions on how to run the EXE file that compilation and linking produced.

Sorry, but we can't help you with that - we have no access to your system at all!
See, you must take a variable to store or copy the value of 'length*breadth'.
You can do it like this:
Copy Code
int length, breadth, area;
...
area = length*breadth;
printf("%d\n", area);
Comments
No, the code as written works fine.

Add your solution here

Preview

Existing Members

Sign in to your account

...or Join us

Download, Vote, Comment, Publish.

Your Email   Password  

 

Your Email   Optional Password  

StrengthToo short

 

I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the CodeProject newsletters
When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK