Wednesday 26 April 2017

mathematical functions in c

// 1.
        #include <stdio.h>
        #include <math.h>
        void main()
        {
            int k = pow(2, 4);
            printf("%d\n", k);
        }

// This program outputs 2 power 4 as 16

//2.

        #include <stdio.h>
        #include <math.h>
        void main()
        {
            int k = fabs(-57);
            printf("%d\n", k);
        }
// This program outputs -57 absolute value as 57


//3.

        #include <stdio.h>
        #include <math.h>
       
        void main()
        {
        int k = sqrt(100);
        clrscr();
        printf("%d\n", k);
        getch();
        }
// This program outputs 100 square root 10 as result

//4.

        #include <stdio.h>
        #include <math.h>
        int main()
        {
            int i = 90;
            printf("%f\n", sin(i));
            return 0;
        }
// caliculates sin90 function


//5. log caliculation

        #include <stdio.h>
        #include <math.h>
        int main()
        {
            int i = 10;
            printf("%f\n", log10(i));
            return 0;
        }

Random Numbers in C

1)  In the below program everytime program is run different numbers are generated.

        #include <stdio.h>
        int main()
        {
            srand(time(NULL));
            printf("%d\n", rand());
            return 0;
        }


2)      
2) the output of this C code is to print an integer between 0-999 including 0 and 999.

        #include <stdio.h>
        #include <stdlib.h>
        int main()
        {
            printf("%d\n", rand() % 1000);
            return 0;
        }