Header Ads Widget

Ticker

6/recent/ticker-posts

Write a program to find area of triangle(a=h*b*.5) a = area h = height b = base Write a program to calculate simple interest (i = (p*r*n)/100 ) i = Simple interest p = Principal amount r = Rate of interest n = Number of years

 

CVM Computer Programming with C
Practical-2

Write a program to find area of triangle(a=h*b*.5)
a = area,h = height,b = base

Logic to find area of a triangle

Below is the step by step descriptive logic to find area of a triangle.

  1. Input base of the triangle. Store in some variable say b(base).
  2. Input height of the triangle. Store in some variable say h(height).
  3. Use triangle area formula to calculate area i.e. a = b * h * 05
  4. Print the resultant value of area.
Solution
#include<stdio.h>
int main()
{
float a,h,b;
printf("\n Enter height :");
scanf("%f",&h);
printf("\n Enter base :");
scanf("%f",&b);
a=b*h*0.5;
printf("\n The Area of triangle = %.2f",a);
return 0;
}
Output

 

Write a program to calculate simple interest (i = (p*r*n)/100 )
i = Simple interest
p = Principal amount
r = Rate of interest
n = Number of years

Logic to calculate simple interest

Step by step descriptive logic to calculate simple interest.

  1. Input principle amount in some variable say p(principle)
  2. Input years  in some variable say n(years).
  3. Input rate in some variable say r(rate).
  4. Find simple interest using formula I =( p * r * n) / 100 ).
  5. Finally, print the resultant value of I(intrest).
Solution
#include <stdio.h>
int main()
{
int n;
float p, r, I;
printf("\n Enter Amount :");
scanf("%f",&p);
printf("\n Enter No of Years :");
scanf("%d",&n);
printf("\n Enter Rate :");
scanf("%f",&r);
I = (p*r*n)/100;
printf("\n Interest = %.2f",I);
return 0;
}
Output

Post a Comment

0 Comments