All pastes #762738 Raw Edit

a triangular program

public c v1 · immutable
·published 2007-11-05 21:38 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <math.h>int calcperim(int sides[]) //{    int retperim = 0;    for (int i = 0; i <3; i++)    {        retperim += sides[i];    }    return retperim;}float calcarea(int sides[], int perim){      float s = perim/2;      return sqrt(s*(s - sides[0])*(s - sides[1])*(s - sides[2]));}        int main(int argc, char *argv[]){  int sides[3];  int perimeter = 0;  int response;  char yesno;  char yesno1;  int exit =0;  int inpdone =0;  int inpvalid =0; while (!exit){  printf("Please enter the lengths of the three sides of a triangle:\n");  printf("Side 1:");  scanf("%d",sides);  printf("\nSide 2:");  scanf("%d",&sides[1]);  printf("\nSide 3:");  scanf("%d",&sides[2]); while (response ){  printf("1:Find the perimeter of the triangle.\n2:Find if the triangle is right angled or not.\n3:Find the area of the triangle\nPlease enter the number of the option you want(0 to exit):");  scanf("%d",&response);  switch (response){         case 1: printf("The perimeter is:%d\n",calcperim(sides));                   inpvalid = 1;                 break;         case 2: printf("You pressed 2\n");                   inpvalid = 1;                 break;         case 3: printf("The area is:%d\n",calcarea(sides, calcperim(sides)));                   inpvalid = 1;                 break;         case 0: break;         default: printf("Please enter a number from the menu:");                                    break;                  }                  }                       printf("\nDo you want to try a new triangle?(y/n):");  scanf("%c",&yesno1);  printf("\n");  switch (yesno1){         case 'n': exit = 1;                   break;         case 'N': exit = 1;                   break;                   }}      return 0;}