Monday, 7 January 2013

Hero’s Formula is A method for calculating the area of a triangle when you know the lengths of all three sides. Let a, b, c be the lengths of the sides of a triangle. The area is given by: where


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,p,A;
printf("enter a,b&c=");
scanf("%f%f%f",&a,&b,&c);
p=(a+b+c)/2;
A=sqrt(p*(p-a)*(p-b)*(p-c));
printf("p=%f\nA=%f",p,A);
getch();
}

Write a c code that will calculate the roots of a quadratic equation Hint: d = sqrt (b 2 -4ac), and the roots are: x1 = (–b + d)/2a and x2 = (–b – d)/2a (use sqrt function from cmath.h )


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,x1,x2,disc;
printf("enter a,b&c");
scanf("%f%f%f",&a,&b,&c);
disc=(b*b)-(4*a*c);
if(disc>0)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("x1=%f\nx2=%f",x1,x2);
}
else
printf("invalid values");
getch();

}

The manager of the Lakeview Hotel wants a program that calculates and displays a guest's total bill. Each guest pays a room charge that is based on a per-night rate. For example if the per night rate is $100 and the guest stays two nights, the room charge is $200.Customer also may incur a one-time room service charge and a one-time telephone charge.


#include<stdio.h>
#include<conio.h>
void main()
{
int a=100,n,bill,t,rs;
printf("enter rupees per night:");
scanf("%d",&rs);
printf("enter telephone charges:");
scanf("%d",&t);
printf("enter days=%d\ntelephone charges=%d\nroom service=%d\n",a,t,rs);
printf("enter no of days: ");
scanf("%d",&n);
bill=((a+t+rs)*n);
printf("\nbill=%d",bill);
getch();
}

When Cheryl Harrison began her trip from Newyork to Wyoming; she filled her car’s tank with gas and reset its trip meter to zero. After traveling 324 miles, Cheryl stopped at a gas station to refuel; the gas tank required 17 gallons. Cheryl wants a program that calculates and displays her car’s gas mileage at any time during the trip. The gas mileage is the number of miles her car was driven per gallon of gas. Write a C code that can implement


#include<stdio.h>
void main()
{
float milge,gallons,gas;

printf("enter milge: ");
scanf("%f",&milge);

printf("enter gallons : ");
scanf("%f", &gallons);

gas=milge/gallons;
printf("gas=%f",gas);
getch();
}

In a town, the percentage of men is 52.The percentage of total literacy is 48.If total percentage of literate men is 35 of the total population, write a program to find the total number of illiterate men and women if the population of town is 80,000.


#include<stdio.h>
void main()
{
float tm=52,tl=48,tlm=35,tp=80000,tlw,ilm,ilw,tw,til;
tm=(tm*tp)/100;
printf("tm=%f\n",tm);
tw=(tp)-(tm);
printf("tw=%f\n",tw);
tlm=(tlm*80000)/100;
printf("tlm=%f\n",tlm);
tl=(tl*80000)/100;
printf("tl=%f\n",tl);
tlw=(tl-tlm);
printf("tlw=%f\n",tlw);
ilm=tm-tlm;
printf("ilm=%f\n",ilm);
ilw=tw-tlw;
printf("ilw=%f\n",ilw);
til=(ilw)+(ilm);
printf("til=%f",til);
getch();
}

Swaping two numbers in c code


#include <stdio.h>

int main()
{
   int x, y, swap;

   printf("Enter 1st value : ");
   scanf("%d", &x);
  printf("Enter 2nd value : ");
   scanf("%d", &y);
   printf("Before Swapping\nx = %d\ny = %d\n",x,y);

   swap = x;
   x = y;
   y = swap;

   printf("After Swapping\nx = %d\ny = %d\n",x,y);
   printf("thankyou for visiting in cheema soft \n");
   getch();
}

Calculator in c code


#include<stdio.h>

void main()

{

 int integer1, integer2, result;
  char a;
printf("choose one of these options ");
printf("calculater\n "); printf("press '+' for addition\npress '-' for subtraction\npress '*' for multiplication\npress'/' for division\npress '%' for percentage\n: ");
   scanf("%c",&a);

  printf("Enter first number: ");
  scanf("%d",&integer1);

  printf("Enter Second number: ");
  scanf("%d",&integer2);

if(a=='+')
{result=integer1+integer2;
printf("Your result is after addition = %d\n",result); }
 else if(a=='-')
{result=integer1-integer2;
printf("Your result is after subtraction = %d\n",result); }
 else if(a=='/')
{result= integer1/integer2;
printf("Your result is after division = %d\n",result); }
 else if(a=='*')
{result= integer1*integer2;
printf("Your result is after multiplication = %d\n",result); }
 else if(a=='%')
{result= integer1%integer2;
printf("Your result is after percentage = %d\n",result); }
else
{printf("invalid entery ");}
 
printf("thankyou for using my software\n ");
 getch();
}