0% found this document useful (0 votes)
11 views3 pages

Simple Program Example

The document contains three C programming examples: the first program swaps the values of two variables without using a third variable, the second calculates the area of a triangle using Heron's formula, and the third finds the largest of three integers. Each program includes input prompts, calculations, and output statements. Sample inputs and outputs are provided for each program to illustrate their functionality.

Uploaded by

ankur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Simple Program Example

The document contains three C programming examples: the first program swaps the values of two variables without using a third variable, the second calculates the area of a triangle using Heron's formula, and the third finds the largest of three integers. Each program includes input prompts, calculations, and output statements. Sample inputs and outputs are provided for each program to illustrate their functionality.

Uploaded by

ankur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. Wap to swap the value of two variables without using third variable.

Program:
#include<stdio.h>
void main()
{
int x,y;
printf("enter the value of x,y");
scanf ("%d%d",&x,&y);
printf("x=%d and y=%d\n",x,y);
y=x*y;
x=y/x;
y=y/x;
printf("x=%d and y=%d",x,y);
}
OUTPUT:

Enter the value of two variables 10 20

x=10 and y=20

y=20 and x=10

[Link] to find out the area of a triangle using the following formula.

Area=√ s (s−a)(s−b)(s−c )

Where S=(a+b+c)/2

Program:

#include<stdio.h>

#include<math.h>

void main()

float a,b,c,s,area;
printf("enter the value of a,b and c");

scanf("%f%f%f",&a,&b,&c);

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

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

printf("s=%f area=%f",s,area);

OUTPUT:
Enter the value of a,b.c

5 6 4

S=7.500000 area=9.91567

[Link] to accepts three integers and prints the largest among them.

Program:
#include <stdio.h>
void main()
{
int A, B, C;

printf("Enter three numbers ");


scanf("%d %d %d", &A, &B, &C);

if(A >B)
{
if (A > C)
{

printf("A is the largest");


}
else
{

printf("C is the largest");


}
}

else if(B>C)
{
printf("B is the largest");
}

else
{
printf("C is the largest");
}

OUTPUT:

Enter three numbers 10 20 30

C is the largest

You might also like