img
Question:
Published on: 22 December, 2024

Write a C program to find the value of Sine(X).

Answer:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int sine(int);
int fact(int);
void main()
{
	int x;
	float result;
	clrscr();
	printf("Enter the value to calculate Sin(x) : ");
	scanf("%d",&x);
	result = sine(x);
	printf("The value of Sin(%d) = %f",x,result);
	getch();
}
int sine(int x)
{
	int i=1,n,m,a,b,cond=0;
	float temp=0;
	printf("\nEnter the iteration : ");
	scanf("%d",&n);
	for(m=1;m<=n;m++)
	{
		a = pow(x,i);
		printf("%d\n",a);
		b = fact(i);
		printf("%d",b);
		if(cond%2==0)
		{
			temp = temp+(a/b);
			printf("%d\n",temp);
			cond = cond+1;
		}
		else
		{
			temp = temp-(a/b);
			printf("%d\n",temp);
			cond = cond+1;
		}
		i = i+2;
	}
	return temp;
}
int fact(int p)
{
	if(p==0)
		return(1);
	else
	{
		p = p*fact(p-1);
	}
	printf("\nFact = %d",p);
	return(p);
}

Random questions