0% found this document useful (0 votes)
3 views16 pages

C Programs

The document contains a series of C programs demonstrating various mathematical calculations, including finding the area of circles and triangles, checking if a number is odd or even, determining the largest or smallest of two numbers, calculating factorials using different loops, generating a Fibonacci series, and performing matrix addition and subtraction. Each program includes input prompts and outputs the results of the calculations. The document serves as a practical guide for basic programming exercises in C.

Uploaded by

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

C Programs

The document contains a series of C programs demonstrating various mathematical calculations, including finding the area of circles and triangles, checking if a number is odd or even, determining the largest or smallest of two numbers, calculating factorials using different loops, generating a Fibonacci series, and performing matrix addition and subtraction. Each program includes input prompts and outputs the results of the calculations. The document serves as a practical guide for basic programming exercises in C.

Uploaded by

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

Experiment No :

/*Program to find the area of circle*/

#include<stdio.h>
#include<conio.h>
#define PI 3.142
void main()
{
float A,r;
clrscr();
printf("enter the value of radius");
scanf("%f",&r);
A=PI*r*r;
printf("Area of circle=%f",A);
getch();
}

Output:
r=3.0
A=28.278
/* c program for to calculate the area of triangle when base and
height is given*/

#include<stdio.h>
#include<conio.h>
void main ()
{
float base,height,area;
clrscr();
printf("Enter base of triangle :");
scanf("%f",&base);
printf("Enter height of triangle :");
scanf("%f",&height);
area=(base*height)/2;
printf("Area of triangle = %3f [Link]",area);
getch();
}

Output:
/* c program for calculating area of triangle when sides are
given*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,s,area;
clrscr();
printf("Enter the sides of triangle: \n");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of triangle=%3f sq,units",area);
getch();
}

Output:
Experiment No :

/* c program for to check whether given number is odd or even */

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter the number:\n");
scanf("%d",&n);
if (n%2==0)
printf("%d is the even number\n",n);
else
printf("%d is the odd number\n",n);
getch();
}

Output:
/*program for to check whether given number is positive or
negative*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter the number");
scanf("%d",&n);
if(n>0)
printf("%d is a postive number",n);
else
printf("%d is a negative number",n);
getch();
}

Output:
Experiment No :

/* c program for to find the largest and smallest of two


number*/

#include<stdio.h>
#include<conio.h>
void main()
{
float num1,num2;
clrscr();
printf("Enter the two number:\n");
scanf("%f%f",&num1,&num2);
if (num1>num2)
printf("%f is larger than %f", num1,num2);
else
printf("%f is the smaller than %f", num1,num2);
getch();
}
Experiment No :

/* c program to find factorial of a number using while loop*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,n,fact=1;
clrscr();
printf("enter the number:\n");
scanf("%d",&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf("factorial=%d",fact);
getch();
}
Output:

/* c program for to find factorial of a number using do-while loop*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,fact;
clrscr();
printf("Enter the number to calculate factorial:\n");
scanf("%d",&n);
fact=1;
i=1;
do
{
fact=fact*i;
i=i++;
}
while(i<=n);
printf("Factorial of %d = %d",n,fact);
getch();
}
Output:
/* c program to find the factorial of a given number using for
loop*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,fact;
clrscr();
printf("Enter the number:\n");
scanf("%d",&n);
fact=1;
for (i=1;i<=n;i++)
{
fact=fact*i;
}
printf("Factorial of %d = %d",n,fact);
getch();
}

Output:
Experiment No :

/* c program tp generate fibobacci series */

#include<stdio.h>
#include<conio.h>
void main()
{
int fib[20],i,n;
clrscr();
fib[0]=0;
fib[1]=1;
printf("Enter the vlaue of n:\n");
scanf("%d",&n);
for(i=2;i<n;i++);
fib[i]=fib[i-2]+fib[i-1];
printf("fibonacci series numbers are:\n");
for(i=0;i<n;i++)
printf("%d",fib[i]);
getch();
}

Output:
Experiment No :

/* c program to find the sum and difference of two matrix */

#include<stdio.h>
#include<conio.h>
void main()
{
int mat1[10][10],mat2[10][10],matsum[10][10],matdiff[10][10];
int n,i,j,row,col;
clrscr();
printf("Enter the order of the matrix:\n");
scanf("%d%d",&row,&col);
printf("Enter the element of the matrix1:\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&mat1[i][j]);
}
}
printf("Enter the element of the matrix2:\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&mat2[i][j]);
}
}
/*computation of sum of two matrices*/
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
matsum[i][j]=mat1[i][j]+mat2[i][j];
}
}
printf("sum of two matrices is:\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",matsum[i][j]);
}
printf("\n");
}
/* computation of difference of two matrices*/
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
matdiff[i][j]=mat1[i][j]-mat2[i][j];
}
}
printf("difference of matrices is:\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",matdiff[i][j]);
}
printf("\n");
}
getch();
}
Output:

You might also like