Thursday, May 30, 2019

program to print prime numbers below 100...in c


/* ***********************************************
    Write a program to print prime numbers below 100

 date:30-05-2019
 created by:ANIL DURGAM

*****************************************************/

#include <stdio.h>
#include <stdlib.h>

void prime_fn(int num);

void main()
{
   int n;

  // printf("Enter a number to check if it is prime\n");
  // scanf("%d",&n);
  for(n=2;n<100;n++)
  {
       prime_fn(n);
  }

   return 0;
}

void prime_fn(int num)
{
    int c;
     for ( c = 2 ; c <= num - 1 ; c++ )
   {
      if ( num%c == 0 )
      {
         //printf("%d isn't prime.\n", num);
     break;
      }
   }
   if ( c == num )
      printf("%d is prime.\n", num);
}

program to find prime number or not using functions in c


/* ***********************************************
    Write a program to find prime number or not using functions

 date:30/-05-2019
 created by:ANIL DURGAM

*****************************************************/

#include <stdio.h>
#include <stdlib.h>

void prime_fn(int num);

void main()
{
   int n;

   printf("Enter a number to check if it is prime\n");
   scanf("%d",&n);
    prime_fn(n);
   return 0;
}

void prime_fn(int num)
{
    int c;
     for ( c = 2 ; c <= num - 1 ; c++ )
   {
      if ( num%c == 0 )
      {
         printf("%d isn't prime.\n", num);
     break;
      }
   }
   if ( c == num )
      printf("%d is prime.\n", num);
}

program to find prime number or not ...in c


/* ***********************************************
    Write a program to find prime number or not

 date:30-05-2019
 created by:ANIL DURGAM

*****************************************************/

#include <stdio.h>
#include <stdlib.h>

main()
{
   int n, c = 2;

   printf("Enter a number to check if it is prime\n");
   scanf("%d",&n);

   for ( c = 2 ; c <= n - 1 ; c++ )
   {
      if ( n%c == 0 )
      {
         printf("%d isn't prime.\n", n);
     break;
      }
   }
   if ( c == n )
      printf("%d is prime.\n", n);

   return 0;
}


openGL testing

#include <windows.h>
#include <gl/gl.h>

LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
void EnableOpenGL(HWND hwnd, HDC*, HGLRC*);
void DisableOpenGL(HWND, HDC, HGLRC);


int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;

    /* register window class */
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "GLSample";
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;


    if (!RegisterClassEx(&wcex))
        return 0;

    /* create main window */
    hwnd = CreateWindowEx(0,
                          "GLSample",
                          "OpenGL Sample",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          256,
                          256,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);

    /* enable OpenGL for the window */
    EnableOpenGL(hwnd, &hDC, &hRC);

    /* program main loop */
    while (!bQuit)
    {
        /* check for messages */
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            /* OpenGL animation code goes here */

            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glClear(GL_COLOR_BUFFER_BIT);

            glPushMatrix();
            glRotatef(theta, 0.0f, 0.0f, 1.0f);

            glBegin(GL_TRIANGLES);

                glColor3f(1.0f, 0.0f, 0.0f);   glVertex2f(0.0f,   1.0f);
                glColor3f(0.0f, 1.0f, 0.0f);   glVertex2f(0.87f,  -0.5f);
                glColor3f(0.0f, 0.0f, 1.0f);   glVertex2f(-0.87f, -0.5f);

            glEnd();

            glPopMatrix();

            SwapBuffers(hDC);

            theta += 1.0f;
            Sleep (1);
        }
    }

    /* shutdown OpenGL */
    DisableOpenGL(hwnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow(hwnd);

    return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_CLOSE:
            PostQuitMessage(0);
        break;

        case WM_DESTROY:
            return 0;

        case WM_KEYDOWN:
        {
            switch (wParam)
            {
                case VK_ESCAPE:
                    PostQuitMessage(0);
                break;
            }
        }
        break;

        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }

    return 0;
}

void EnableOpenGL(HWND hwnd, HDC* hDC, HGLRC* hRC)
{
    PIXELFORMATDESCRIPTOR pfd;

    int iFormat;

    /* get the device context (DC) */
    *hDC = GetDC(hwnd);

    /* set the pixel format for the DC */
    ZeroMemory(&pfd, sizeof(pfd));

    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW |
                  PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;

    iFormat = ChoosePixelFormat(*hDC, &pfd);

    SetPixelFormat(*hDC, iFormat, &pfd);

    /* create and enable the render context (RC) */
    *hRC = wglCreateContext(*hDC);

    wglMakeCurrent(*hDC, *hRC);
}

void DisableOpenGL (HWND hwnd, HDC hDC, HGLRC hRC)
{
    wglMakeCurrent(NULL, NULL);
    wglDeleteContext(hRC);
    ReleaseDC(hwnd, hDC);
}

find the LCM and HCF of two numbers in c

/*************************************************
    Write a Program to find the LCM and HCF of two numbers

 date:30/-05-2019
 created by:ANIL DURGAM

*****************************************************/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,y,a,b;
     printf("Enter two numbers");
     scanf("%d %d",&x,&y);
      a=x;
      b=y;
      while(a!=b)
        {
            if(a<b)
                a=a+x;
            else
                b=b+y;
        }
        printf("LCM of %d and %d is %d\n",x,y,a);
         a=x; b=y;
         while(a!=b)
            {
                if(a>b)
                    a=a-b;
                else
                    b=b-a;
                }
                printf("HCF of %d and %d is. %d\n", x, y, a) ;

    return 0;
}

triad numbers in c

/*************************************************
    Write a program to find triad numbers..
1.Each number is a three digit number.
2.All the digits in the three numbers (total 9 digits) should be different.
3.Second number should be twice the first number and third number should be thrice the first number.
  For example
  219 438 657
  267 534 801

 date:30/-05-2019
 created by:ANIL DURGAM

*****************************************************/

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int m,n,p,num;
   int i,k,dl,d2,d3;
    for(num=100;num<=999/3;num++)/*Loop A*/
        {
            for (i=num; i<=3 *num; i+=num) /* loop B */
             {
                 k=i;
                 dl=k%10;
                 k/=10;
                 d2=k%10;
                 k/=10;
                 d3=k%10;
                 k/=10;
                 if(dl==d2 || d2==d3 || d3==dl)
                    goto nextnum;
            } /*Endof loop B*/

            for(m=num;m>0;m/=10) /*Loop c*/
                {
                    dl=m%10;
                    for(n=num*2;n>0;n/=10) /*Loop D*/
                    {
                        d2=n%10;
                        for(p=num*3;p>0;p/=10) /*Loop E*/
                        {
                            d3=p%10;
                            if(dl==d2 || d2==d3 || dl==d3)
                                goto nextnum;
                        } /*End of Loop E*/
                    } /*End of Loop D*/
                }/*End of loop C*/
                 nextnum:
                            printf("%d\t%d\t%d\n",num,num*2,num*3);

        } /*End of loop A*/

    //return 0;
}

find date of birth.......day.... in c

/* ***********************************************
    Write a program to find date of birth.......day....


 date:30/-05-2019
 created by:ANIL DURGAM

*****************************************************/

#include <stdio.h>
#include <stdlib.h>

#include<stdio.h>
#include<stdlib.h>

int main() {
 int d, m, y, year, month, day, i;

 printf("Enter date of birth (DD MM YYYY) :");
 scanf("%d %d %d", &d, &m, &y);
 if( (d > 31) || (m > 12) || (y < 1900 || y >= 2100) )
 {
    printf("INVALID INPUT. Please enter a valid date between 1900 and 2100");
    exit(0);
 }

    year = y-1900;
    year = year/4;
    year = year+y-1900;

    switch(m)
        {
            case 1:
            case 10:
            month = 1;
            break;
             case 2:
             case 3:
             case 11:
             month = 4;
             break;
             case 7:
             case 4:
             month = 0;
             break;
             case 5:
             month = 2;
             break;
             case 6:
             month = 5;
             break;
             case 8:
             month = 3;
             break;
             case 9:
             case 12:
             month = 6;
             break;
 }

         year = year + month;
         year = year + d;
         /* Need to make sure extra day is not needed in leap year for dates before March */
         if(( y > 1900 ) && ( y % 4 == 0 ) && ( m < 2 ) )
         year--;
         day = year % 7;

         switch(day)
         {
             case 0:
             printf("Day is SATURDAY\n");
             break;
             case 1:
             printf("Day is SUNDAY\n");
             break;
             case 2:
             printf("Day is MONDAY\n");
             break;
             case 3:
             printf("Day is TUESDAY\n");
             break;
             case 4:
             printf("Day is WEDNESDAY\n");
             break;
             case 5:
             printf("Day is THURSDAY\n");
             break;
             case 6:
             printf("Day is FRIDAY\n");
             break;
         }

 return 0;
}

program to find given alphabet is vowel or consonant using switch in c

/* this is the program to find
    given alphabet is vowel or consonant using switch


 date:30/-05-2019
 created by:ANIL DURGAM

*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char i;
    printf("please enter your choice\n");
    scanf("%c",&i);
    switch(i)
    {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
            printf("you have entered vowel\n");
            break;

        default:
            printf("you have entered consonant\n");
    }
    return 0;
}



python class topic video