C program for sin cos and tan function

C program for sin function

C program for cos function

C program for tan function

Program:-



#include<stdio.h>
#include<math.h>

void main()
{
  float deg,rad;
  char n;
  
  //menu for choose to sin, cos and tan
  printf("**Menu**\n");
  printf("S/s---->sin(x)\nC/c---->cos(x)\nT/t----->tan(x)\n");
  printf("Enter your choice\n"); 
  scanf("%c",&n);

  //Read deg 
  printf("Enter angle in degree\n");
  scanf("%f",&deg);

  rad=(3.142/180)*deg;
 
 //print result
 switch(n)
 {
  case 'S':
  case 's':printf("sin(%f)=%f\n",deg,sin(rad));
      break;
  case 'C':
  case 'c':printf("cos(%f)=%f\n",deg,cos(rad));
      break;
  case 'T':
  case 't':printf("tan(%f)=%f\n",deg,tan(rad));
      break;
  default:printf("Invalid\n");
 }

 getch();
}
     
 

Click here to download source code

Output:-

**Menu**
S/s===>sin(x)
C/c===>cos(x)
T/t===>tan(x)
Enter your choice
1
Enter angle in degree
0.5
sin(0.5)=0.0087

**Menu**
S/s===>sin(x)
C/c===>cos(x)
T/t===>tan(x)
Enter your choice
2
Enter angle in degree
0.5
cos(0.5)=0.99997

Leave reply

Add your comments here

Back to Top