Skip to content

Instantly share code, notes, and snippets.

@Welding-Torch
Created June 18, 2022 17:16
Show Gist options
  • Save Welding-Torch/4779bcda4067fea702bdd8925f4412ab to your computer and use it in GitHub Desktop.
Save Welding-Torch/4779bcda4067fea702bdd8925f4412ab to your computer and use it in GitHub Desktop.
Assignment list for CP-Practical
/******************************************************************************
18 June, 2022
Write a program to find the area of a triangle using Heron's Formula.
3 sides of a triangle
Herons formula is s=(a + b + c)/2 and then sqrt(s*(s-a)*(s-b)*(s-c))
*******************************************************************************/
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
int a, b, c, s;
float area;
printf("Enter the values of a, b, and c: ");
scanf("%d%d%d", &a, &b, &c);
s = a + b + c;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("\n The Area of the triangle is %d", area);
getch();
}
/******************************************************************************
18 June, 2022
Write a program to find the biggest of three numbers.
*******************************************************************************/
#include <stdio.h>
#include <conio.h>
void main()
{
int a, b, c;
printf("\nEnter three numbers: ");
scanf("%d%d%d", &a, &b, &c);
if (a>b)
if (a>c)
printf("\nBiggest number is %d", a);
else
printf("\nBiggest number is %d", c);
else if (b>c)
printf ("\nBiggest number is %d", b);
else
printf("\nBiggest Number is %d", c);
getch();
}
/******************************************************************************
18 June, 2022
Write a program to display the numbers from 1 to 100 that are divisible by 4 and 6.
*******************************************************************************/
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
for (i=0;i<=100;i++)
{
if (i%4==0 && i%6==0)
{
printf("\nDivisible by 4 and 6: %d", i);
}
}
}
/******************************************************************************
18 June, 2022
Write a program to display the prime numbers in between 75 to 150
*******************************************************************************/
#include <stdio.h>
#include <conio.h>
void main()
{
int i, x, count;
for (i=75;i<=150;i++)
{
for (x=1;x<=i;x++)
{
if (i%x==0)
count++;
}
if (count==2)
{
printf("\n%d is a Prime Number", i);
}
count=0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment