Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6635467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:03:28+00:00 2026-05-25T23:03:28+00:00

The following is the source code of a program which calculates the area of

  • 0

The following is the source code of a program which calculates the area of a triangle when the sides are given.

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int a,b,c;
float s,area;
clrscr();
printf("Enter the lengths of the sides of the triangle:\n");
scanf("%d%d%d",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area=%f",area);
getch();
}

I used the Turbo C++ compiler Version 3.0 to compile the program. When I give the sides as 10, 10 and 10, I get the area as 43.301270 which is correct. But when I plug the values as 1,1 and 1, the program gives the area as 0.000000 which is obviously wrong. Further, when I plug in the values as 3,3 and 3 I get the area as 2.000000 which is wrong.

Does anyone know the reason for the program’s erratic behavior? How can it be corrected? I have uploaded the program as a Zip file.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:03:29+00:00Added an answer on May 25, 2026 at 11:03 pm

    You are using integer arithmetic for the calculation of s and suffering from truncation. Change your program like this to use floating point arithmetic.

    s=(a+b+c)/2f;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code static void Main(string[] args) { //var source = BlockingMethod();
I created 2 C program source code files and one header file which just
The following source code alerts the following results: Internet Explorer 7 : 29 Firefox
Visual Studio 2008 I am using the following source code that compiles ok using
I get the following compilation error with the following source code: Compilation Error: Type
I have the following SVG source code that generates a number of boxes with
I'm writing an XML file with the following code: Source source = new DOMSource(rootElement);
I have seen a web page source code containing the following css declaration at
Frequently I come across the following statements in C/C++ source code: $Id: lzio.c,v 1.24
I downloaded the qt embedded demo source code recently on my linux machine. Following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.