Skip to content

Instantly share code, notes, and snippets.

@AungWinnHtut
Created April 13, 2018 10:57
Show Gist options
  • Save AungWinnHtut/0b3616527bc2765a5cca146ef71b9513 to your computer and use it in GitHub Desktop.
Save AungWinnHtut/0b3616527bc2765a5cca146ef71b9513 to your computer and use it in GitHub Desktop.
This program is to teach beginner to understand 1-lookup talbe 2-external variable 3-array 4-structure 5-return datatype
/*
This program is to teach beginner
to understand
1-lookup talbe
2-external variable
3-array
4-structure
5-return datatype
Programmer: Dr. Aung Win Htut (Green Hackers)
https://www.facebook.com/GreenHackersOTC/
Date: 13-04-2018
*/
#include<stdio.h>
#include<conio.h>
struct TRIGO trigoval(int ang);
int ang=45;
int index=-1;
int angle[8] = { 0, 30, 45, 60, 90, 180, 270, 360 };
float sine[8] = { 0, 0.5, 0.707, 0.866, 1, 0, -1, 0 }; //1/sqrt(2)=0.707 sqrt(3)/2 =0.866
float cosine[8] = { 1, 0.866, 0.707, 0.5, 0, -1, 0, 1 }; //1/sqrt(2)=0.707 sqrt(3)/2 =0.866
struct TRIGO{
float sin;
float cos;
};
int main()
{
TRIGO tgo;
tgo = trigoval(ang);
printf("sin(%d)=%f cos(%d)=%f",ang,tgo.sin ,ang,tgo.cos );
getch();
return 0;
}
struct TRIGO trigoval(int ang)
{
int index=-1;
struct TRIGO trigo;
for(int j=0;j<8;j++)
{
if(angle[j]==ang)
{
index=j;
}
}
trigo.sin =sine[index];
trigo.cos =cosine[index];
return trigo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment