Tanti Technology

My photo
Bangalore, karnataka, India
Sandeep Kumar | Founder, Tanti Technologies At Tanti Technologies, I share practical knowledge, hands-on tutorials, and real-world solutions across Python, SQL, Docker, Kubernetes, CI/CD, AWS, Azure, Machine Learning, Generative AI, and Agentic AI. My mission is to simplify complex technologies and provide actionable insights that help developers, engineers, and businesses learn faster, build better, automate smarter, and innovate with confidence. 🚀 Learn • Build • Automate • Innovate Follow Tanti Technologies for practical technology insights and next-generation AI solutions.

Monday, 4 July 2011

C program-2

1 ./* Write a C program to find the area of a triangle, given three sides*/

#include
#include

main()
{
int s, a, b, c, area;
clrscr();

printf("Enter the values of a,b and c\n");
scanf ("%d %d %d", &a, &b, &c);

/* compute s*/

s = (a + b + c) / 2;

area = sqrt ( s * (s-a) * (s-b) * (s-c));

printf ("Area of a triangale = %d\n", area);
}
/*-----------------------------
Output

Enter the values of a,b and c
3
4
5
Area of a triangale = 6
------------------------------*/


**********************************************************************



2. /* Write a C program to find the area of a circl, given the adius*/

#include
#include
#define PI 3.142

main()
{
float radius, area;
clrscr();

printf("Enter the radius of a circle\n");
scanf ("%f", &radius);

area = PI * pow (radius,2);

printf ("Area of a circle = %5.2f\n", area);
}
/*-----------------------------
Output

RUN1
Enter the radius of a circle
3.2
Area of a circle = 32.17

RUN 2
Enter the radius of a circle
6
Area of a circle = 113.11

------------------------------*/


************************************************************************


3. /* Write a C program to find the simple interest , given principle, *
* rate of interest and times*/

#include

main()
{

float p, r, si;
int t;

clrscr();

printf("Enter the values of p,r and t\n");
scanf ("%f %f %d", &p, &r, &t);

si = (p * r * t)/ 100.0;
printf ("Amount = Rs. %5.2f\n", p);
printf ("Rate = Rs. %5.2f%\n", r);
printf ("Time = %d years\n", t);
printf ("Simple interest = %5.2f\n", si);
}
/*-----------------------------
Output
Enter the values of p,r and t
2000
8
3
Amount = Rs. 2000.00
Rate = Rs. 8.00%
Time = 3 years
Simple interest = 480.00

------------------------------*/

*****************************************************************


4. /* Write a C program to check whether a given integer is odd or even*/

#include

main()
{
int ival, remainder;
clrscr();

printf("Enter an integer :");
scanf ("%d", &ival);

remainder = ival % 2;

if (remainder == 0)
printf ("%d, is an even integer\n", ival);
else
printf ("%d, is an odd integer\n", ival);

}
/*-----------------------------
Output

RUN1

Enter an integer :13
13, is an odd integer

RUN2
Enter an integer :24
24, is an even integer

---------------------------------*/

******************************************************************************


5. /* Write a C program to check whether a given integer *
* number is positive or negative*/

#include

main()
{
int number;
clrscr();

printf("Enter a number\n");
scanf ("%d", &number);

if (number > 0)
printf ("%d, is a positive number\n", number);
else
printf ("%d, is a negative number\n", number);

}
/*-----------------------------
Output
Enter a number
-5
-5, is a negative number

RUN2
Enter a number
89
89, is a positive number
------------------------------*/

****************************************************************

No comments:

Post a Comment