Graphiques en C - Applications résolues


1) Dessiner un rectangle rempli.
#include <graphics.h>
int main( )
{
    initwindow(600, 600, "Rectangle");
    bar(500, 500, 100, 100); 
    while (!kbhit( ))
    {
        delay(200);
    }
    return 0;
}

2) Dessiner un rectangle non-rempli.
#include <graphics.h>
int main( )
{
    initwindow(600, 600, " Rectangle");
    rectangle(50,275,150,400);
    setcolor (15);
    while (!kbhit( ))
    {
        delay(200);
    }
    return 0;
}

3) Dessiner un cercle.
#include <graphics.h>
int main( )
{
    initwindow(400, 300, "Cercle");
    circle(100, 50, 40);
    while (!kbhit( ))
    {
        delay(200);
    }
    return 0;
}

4) Dessiner des cercles concentriques.
#include <graphics.h>
 
int main()
{ 
   int gd = DETECT, gm;
   int x = 320, y = 240, radius;
 
   initgraph(&gd, &gm, "C:\\TC\\BGI");
 
   for ( radius = 25; radius <= 125 ; radius = radius + 20)
      circle(x, y, radius);
 
   getch();
   closegraph();
   return 0;
}

5) Dessiner un rectangle avec le coin de gauche-haut, dans le coin de gauche-haut de c’ecran.
#include <graphics.h>
int main( )
{
    initwindow(600, 600, " Rectangle");
    rectangle(0,0,20,50);
 
    while (!kbhit( ))
    {
        delay(200);
    }
    return 0;
}

6) Dessiner un rectangle avec le coin de gauche-haut, dans le coin de gauche-haut de c’ecran. Introduire du clavier la longueur et la largeur.
#include <graphics.h> 	// bibliotheque primitive grafique
#include <stdlib.h>
int main()
{ 
    
   int graphdriver, graphmode;
   int left,top,right,bottom;
   graphdriver = DETECT;
   initgraph(&graphdriver, &graphmode, " ");
   left=top=0;   
   printf("Introduire right: ", right);
   scanf("%d", &right);
   printf("Introduire bottom: ", bottom);
   scanf("%d", &bottom);
   rectangle(left,top,right,bottom);
   getch();
   closegraph();
   return 0;
}

7) Dessiner un rectangle avec le coin de gauche-haut, dans le coin de gauche-haut de c’ecran. Introduire du clavier la longueur et la largeur du clavier.
#include <graphics.h> 	// bibliotheque primitive grafique
#include <stdlib.h>
#include <dos.h>
#include <conio.h> 
int main()
{ 
    int graphdriver, graphmode;
    int x,y;
    
   graphdriver = DETECT;
 
   initgraph(&graphdriver, &graphmode, " ");
   
   printf("Introduire la longueur du rectangle: ", x);
   scanf("%d", &x);
   
   printf("introduire la largeur du rectengle: ", y);
   scanf("%d", &y);
   //initwindow(900, 900, "Dreptunghi");
   rectangle(0,0,x,y);
 
   getch();
   closegraph();
   return 0;
}
OR
#include <graphics.h> 	// bibliotheque primitive grafique
#include <stdlib.h> 
int main()
{ 
   int graphdriver, graphmode;
   int left,top,right,bottom;
   graphdriver = DETECT;
   initgraph(&graphdriver, &graphmode, " ");
   left=0;
   bottom=getmaxy();
   printf("Introduceti right: ", right);
   scanf("%d", &right);
   printf("Introduceti bottom: ", top);
   scanf("%d", &top);
   rectangle(left,top,right,bottom);
   getch();
   closegraph();
   return 0;
}

8) Dessiner un rectangle avec toutes les cottés introduites du clavier.
#include <graphics.h>	 // bibliotheque primitive grafique
#include <stdlib.h> 
int main()
{ 
   int graphdriver, graphmode;
   int left,top,right,bottom; 
   graphdriver = DETECT;
   initgraph(&graphdriver, &graphmode, " ");
   printf("Introduire left: ", left);
   scanf("%d", &left);
   printf("Introduire top: ", top);
   scanf("%d", &top);  
   printf("Introduire right: ", right);
   scanf("%d", &right);
   printf("Introduire bottom: ", bottom);
   scanf("%d", &bottom);
   rectangle(left,top,right,bottom);
   getch();
   closegraph();
   return 0;
}

9) Dessiner un cercle avec l’abscise, l’ordonee si le rayon du cetrcle introduits du clavier.
#include <graphics.h> 	// bibliotheque primitive grafique
#include <stdlib.h>
int main()
{ 
   int graphdriver, graphmode;
   int x,y,radius;
   graphdriver = DETECT;
   initgraph(&graphdriver, &graphmode, " ");
   printf("Introduire x: ", x);
   scanf("%d", &x);
   printf("Introduire y: ", y);
   scanf("%d", &y);
   printf("Introduire radius: ", radius);
   scanf("%d", &radius);
   circle(x,y,radius);
   getch();
   closegraph();
   return 0;
}

10) Dessiner n cercles. Les abscises, les ordonnees et les rayons s’introduire du clavier. On dessine seulement si le cercle est tout dans l’espace de l’ecran.
#include "graphics.h"
#include "conio.h"
#include "stdlib.h" 
int main()
{ 
   int graphdriver, graphmode;
   int x[30],y[30],radius[30];
   int n;  
   graphdriver = DETECT;
   initgraph(&graphdriver, &graphmode, " ");
   printf("Introduire nombre des cercles: ");
   scanf("%d", &n);
   for (int i=0; i<n; i++)
   {
       printf("Cercle %d: ",i+1);
       printf("Introduire x: ");
       scanf("%d", &x[i]);
       printf("Introduire y: ");
       scanf("%d", &y[i]);
       printf("Introduire le rayon: ");
       scanf("%d", &radius[i]);
   }
    
   for (int i=0; i<n; i++)
   if(x[i]>0 && x[i]<getmaxx() && y[i]>0 && y[i]<getmaxy() && (x[i]+radius[i])<getmaxx() && 
   (x[i]>radius[i]) && (y[i]+radius[i])<getmaxy() && (y[i]>radius[i]))
   circle(x[i],y[i],radius[i]);
   getch();
   closegraph();
   return 0;
}

11) Dessiner une elipse.
#include <graphics.h> // bibliotheque primitive grafique
#include <stdlib.h>
int main()
{ 
   int graphdriver, graphmode;
   int x, y, stangle, endangle, xradius, yradius;
   int n;
   graphdriver = DETECT;
   initgraph(&graphdriver, &graphmode, " ");
   ellipse(500, 100,0,360, 100,50);
   getch();
   closegraph();
   return 0;
}

12) Dessiner une elipse avec tout introduit du clavier.
#include <graphics.h> 	// bibliotheque primitive grafique
#include <stdlib.h>
int main()
{ 
   int graphdriver, graphmode;
   int x, y, stangle, endangle, xradius, yradius;
   graphdriver = DETECT;
   initgraph(&graphdriver, &graphmode, " ");
   printf("Introduire x: ");
   scanf("%d", &x);
      printf("Introduire y: ");
   scanf("%d", &y);
      printf("Introduire stangle: ");
   scanf("%d", &stangle);
      printf("Introduire endangle: ");
   scanf("%d", &endangle);
      printf("Introduire xradius: ");
   scanf("%d", &xradius);
      printf("Introduire yradius: ");
   scanf("%d", &yradius);
   ellipse(x, y, stangle, endangle, xradius, yradius);
   getch();
   closegraph();
   return 0;
}

13) Dessiner une elipse avec son centre dans le centre de l’ecran et tout introduit du clavier. Seulement si le dessin se trouve.
#include <graphics.h> // biblioteque primitive grafique
#include <stdlib.h>
int main()
{ 
   int graphdriver, graphmode;
   int x, y, stangle, endangle, xradius, yradius;
   graphdriver = DETECT;
   initgraph(&graphdriver, &graphmode, " ");
   x=getmaxx()/2;
   y=getmaxy()/2;
      printf("Introduire stangle: ");
   scanf("%d", &stangle);
      printf("Introduire endangle: ");
   scanf("%d", &endangle);
      printf("Introduire xradius: ");
   scanf("%d", &xradius);
      printf("Introduire yradius: ");
   scanf("%d", &yradius);
   if ( (xradius<getmaxy()/2) && (yradius<getmaxx()/2) )
   {
    ellipse(x, y, 0, 350, xradius, yradius);
    getch();
    closegraph();
   }
   else
   {
	closegraph();
	printf("\n\nL’elipse n’a pas de place dans l’ecran.\n");
	getch();
   }
}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.