BCA PRACTICAL SLIPS SOLUTION
Slip2
Q1. Write a C program to accept radius of a circle and display the area and circumference
of a circle. [15 Marks]
#include<stdio.h>
int main() {
int rad;
float PI = 3.14, area, ci;
printf("\nEnter radius of circle: ");
scanf("%d", &rad);
area = PI * rad * rad;
printf("\nArea of circle : %f ", area);
ci = 2 * PI * rad;
printf("\nCircumference : %f ", ci);
return (0);
}
------------------------------------------------------------------------
Q2. Write a program to calculate sum of following series up to n terms. [25 Marks]
Sum=X+X2/2!+X3/3!+……
(Note: Write separate user defined function to calculate power and factorial)
#include<math.h>
#include<stdio.h>
int fact(int index)
{
int f = 1, i;
for(i = 1; i <= index; i ++)
{
f = f*i;
}
return f;
}
// Driver Code
void main()
{
int x = 1;
int n = 2;
double sum = 0, m;
// Sum of n-1 terms starting from 2nd term
int i;
for (i = 1; i < =n; i++) {
m = pow(x, i) / fact(i);
sum = sum + m;
}
printf("\n%.4f", sum);
getch();
}
No comments:
Post a Comment