Showing posts with label numbers. Show all posts
Showing posts with label numbers. Show all posts

Monday, 31 March 2014

C Programming graphics | Countdown using C graphics

C Programming graphics | Countdown using C graphics

Source code:-)

#include <graphics.h>
#include <dos.h>
#include <conio.h>

int main()
{
   int gd = DETECT, gm, i;
   char a[5];

   initgraph( &gd, &gm, "C:\\TC\\BGI");

   settextjustify( CENTER_TEXT, CENTER_TEXT );
   settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
   setcolor(RED);

   for (i = 30; i >=0; i--)
   {
      sprintf(a,"%d",i);
      outtextxy(getmaxx()/2, getmaxy()/2, a);
      delay(1000);

      if ( i == 0 )
         break;
      cleardevice();
   }

   getch();
   closegraph();
   return 0;
}

C program | To generate random numbers

 C program | To generate random numbers

Source code:-)

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

int main() {
  int c, n;

  printf("Ten random numbers in [1,100]\n");

  for (c = 1; c <= 10; c++) {
    n = rand()%100 + 1;
    printf("%d\n", n);
  }

  return 0;
}

C programs | Swapping of two numbers without third(temp) variable in C

C programs | Swapping of two numbers without third(temp) variable in C

Source Code:-)

#include <stdio.h>

int main()
{
   int a, b;

   printf("Enter two integers to swap\n");
   scanf("%d%d", &a, &b);

   a = a + b;
   b = a - b;
   a = a - b;

   printf("a = %d\nb = %d\n",a,b);
   return 0;
}

C Programs | Swapping of two numbers in c

C programs | Swapping of two numbers in c

Source code:-)

#include <stdio.h>

int main()
{
   int x, y, temp;

   printf("Enter the value of x and y\n");
   scanf("%d%d", &x, &y);

   printf("Before Swapping\nx = %d\ny = %d\n",x,y);

   temp = x;
   x    = y;
   y    = temp;

   printf("After Swapping\nx = %d\ny = %d\n",x,y);

   return 0;
}

Output:-)

Enter the value of x and y

3

6

Before swapping 

x=3 

y=6 

After swapping


x=6

y=3