Write a program to read a double-type value x that represents angle in radians and a character-type variable T that represents the type of trigonometric function and display the value of
(a) sin(x), if s or S is assigned to T,
(b) cos(x), if c or C is assigned to T, and
(c) tan(x), if t or T is assigned to T
using if.......else statement
#include <stdio.h>
#include <math.h>
void main()
{
float x,result;
char T;
clrscr();
printf("Enter the trignometric function\nS for sin,C for cos and T for tan\n and its angle:");
scanf("%c %f",&T,&x);
if(T=='s'||T=='S')
{
result= sin(x);
printf("Result = %f",result);
}
else
if(T=='c'||T=='C')
{
result=cos(x);
printf("Result = %f",result);
}
else
if(T=='t'||T=='T')
{
result=tan(x);
printf("Result = %f",result);
}
else
printf("Wrong Input");
getch();
}
(a) sin(x), if s or S is assigned to T,
(b) cos(x), if c or C is assigned to T, and
(c) tan(x), if t or T is assigned to T
using if.......else statement
#include <stdio.h>
#include <math.h>
void main()
{
float x,result;
char T;
clrscr();
printf("Enter the trignometric function\nS for sin,C for cos and T for tan\n and its angle:");
scanf("%c %f",&T,&x);
if(T=='s'||T=='S')
{
result= sin(x);
printf("Result = %f",result);
}
else
if(T=='c'||T=='C')
{
result=cos(x);
printf("Result = %f",result);
}
else
if(T=='t'||T=='T')
{
result=tan(x);
printf("Result = %f",result);
}
else
printf("Wrong Input");
getch();
}
No comments:
Post a Comment