0% found this document useful (0 votes)
15 views8 pages

Pooja DCBNST

The document contains programs written in C language to calculate factorial using recursion, sum of n terms of e^x, roots of quadratic equation and errors. For each program, the problem statement, objective, formula used and source code is provided along with sample output.

Uploaded by

dhamip333
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)
15 views8 pages

Pooja DCBNST

The document contains programs written in C language to calculate factorial using recursion, sum of n terms of e^x, roots of quadratic equation and errors. For each program, the problem statement, objective, formula used and source code is provided along with sample output.

Uploaded by

dhamip333
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
You are on page 1/ 8

1

Name: Pooja Dhami


Roll no.: 50
Course: BCA
Section: C2

Program 1:
Problem Statement: Write a C program to calculate the Factorial of a given number using
recursion.
Objective: To understand the concept of recursion.
Formula Used:
Source Code:
#include <Stdio.h>
int fact(int num)
{
if (num <= 1)
return 1;
else
return num * fact(num - 1);
}
int main()
{
int num, k;
printf("Enter a number: ");
scanf("%d", &num);
k = fact(num);
printf("Factorial of number is: %d\n", k);
return 0;
}

1
2
Name: Pooja Dhami
Roll no.: 50
Course: BCA
Section: C2

OUTPUT:
PS C:\Users\manoj\Desktop\CBNST> gcc recursion.c
PS C:\Users\manoj\Desktop\CBNST> ./a.exe
Enter a number: 7
Factorial of number is: 5040

2
3
Name: Pooja Dhami
Roll no.: 50
Course: BCA
Section: C2

Program 2:
Problem Statement: Write a C program to calculate the sum of n terms of e^x.
Objective: To understand the concept of sum of n terms of e^x.
Formula Used:
Source Code:
#include <stdio.h>
void main()
{
float power;
printf("Enter the Power of e: \n");
scanf("%f", &power);
float accuracy = 25;
float answer = 1;
float temp = 1;
int i;
for (i = 1; i <= accuracy; i++)
{
temp = (temp * power) / i;
answer = answer + temp;
}
printf("%f", answer);
}

3
4
Name: Pooja Dhami
Roll no.: 50
Course: BCA
Section: C2

OUTPUT:
PS C:\Users\manoj\Desktop\CBNST> gcc sum.c
PS C:\Users\manoj\Desktop\CBNST> ./a.exe
Enter the Power of e: 6
403.428711

4
5
Name: Pooja Dhami
Roll no.: 50
Course: BCA
Section: C2

Program 3:
Problem Statement: Write a C program to calculate the roots of an quadratic equation .
Objective: To understand the concept of Quadratic Equation.
Formula Used:
Source Code:
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, d, r1, r2;
printf("Enter the value for a,b,c:\n");
scanf("%f%f%f", &a, &b, &c);
d = b * b - 4 * a * c;
if (d == 0)
{
printf("The roots are real & equal:\n");
r1 = b / (2 * a);
r2 = b / (2 * a);
printf("root for 1 is%f and root for 2 is%f\n", r1, r2);
}
else
{
printf("The roots are imgm:\n");
}
}

5
6
Name: Pooja Dhami
Roll no.: 50
Course: BCA
Section: C2

OUTPUT:
PS C:\Users\manoj\Desktop\CBNST> gcc quadratic.c
PS C:\Users\manoj\Desktop\CBNST> ./a.exe
Enter the value for a , b and c:
2
3
7
The roots are imaginary.

6
7
Name: Pooja Dhami
Roll no.: 50
Course: BCA
Section: C2

Program 4:
Problem Statement: WAP IN C TO FIND RELATIVE ERROR , ABSOLUTE ERROR and
PERCENTAGE ERROR
Objective: To understand the concept of errors
Formula Used:
Source Code:
#include<stdio.h>
#include<math.h>
int main()
{
float a ,b,AE,RE ,PE;
printf("Enter the true value \n");
scanf("%f",&a);
printf("Enter the approx value \n");
scanf("%f",&b);
AE = a-b;
RE = AE/a;
PE = RE*100;
printf("Absolute Error = %f \n" , AE);
printf("Relative Error = %f \n" , RE);
printf("Percentage Error = %f \n" , PE);
return 0;
}

7
8
Name: Pooja Dhami
Roll no.: 50
Course: BCA
Section: C2

OUTPUT:
/tmp/Aage6AYsjP.o
Enter the true value
123
Enter the approx value
123.32
Absolute Error = -0.320000
Relative Error = -0.002602
Percentage Error = -0.260162

You might also like