Lecture1 - Example
Lecture1 - Example
-271
Presented By
Saadman Sakib
Lecturer,
Department of CSE,
CUET
Generations of Programming Language
User-Defined
#include <stdio.h> Functions
#include
<math.h>
float area (float a,
float b,float c);
int main( )
{
float a,b,c;
printf("Enter size of each sides of triangle: ");
scanf("%f%f%f",&a,&b,&c);
printf("Area of the triangle is:
%f",area(a,b,c));
return 0;
}
float area (float a, float b,float c)
{
float s=(a+b+c)/2;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
C program to calculate the distance between two points
#include <stdio.h>
#include <math.h>
float dist(float *x1, float *y1, float *x2, float *y2) Pointers
{
return sqrt((*x2 - *x1) * (*x2 - *x1) + (*y2 - *y1) * (*y2 -
*y1));
}
int main()
{
float result, a, b, c, d;
printf("\nEnter The Coordinates of Point A:\
n"); scanf("%f %f",&a,&b);
printf("\nEnter The Coordinates of Point B:\
n"); scanf("%f %f",&c,&d);
printf("\nDistance between Points A and B: %f\n",dist(&a, &b, &c,
&d)); return 0;
}
C Program to convert temperature from Celsius to Fahrenheit
#include <stdio.h>
int main()
{
float C,F;
printf("Enter temperature in Celsius:
"); scanf("%f",&C);
F= (C*9/5)+32;
printf("%.2f Celsius = %.2f Fahrenheit",C,F);
return 0;
}