begin process at 2012 05 27 19:08:34
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > UN SAPIN DE NOEL

UN SAPIN DE NOEL


 Information sur la source

 Description

Il dessine un joli sapin de noel sur la sortie standard :)

Source

  • /*
  • ** sapin.c for Sapin de Noel
  • **
  • ** Made by ali mdidech
  • **
  • **
  • ** Started on Sat Oct 11 14:19:02 2003
  • ** Last update Tue Oct 21 03:37:25 2003
  • */
  • #include <stdio.h>
  • void my_putchar(char c)
  • {
  • write(1, &c, 1);
  • }
  • int last_line(int taille)
  • {
  • int i;
  • int jump;
  • int lastline;
  • lastline = 7;
  • jump = 6;
  • for (i = 1; i < taille; i++)
  • {
  • if ((i % 2) != 0)
  • lastline += jump;
  • else if (i != 1)
  • {
  • jump += 2;
  • lastline += jump;
  • }
  • }
  • return (lastline);
  • }
  • int first_line(int taille)
  • {
  • int i;
  • int jump;
  • int firstline;
  • firstline = 1;
  • jump = 4;
  • for (i = 1; i < taille; i++)
  • {
  • if ((i % 2) != 0)
  • firstline += jump;
  • else if (i != 1)
  • {
  • jump += 2;
  • firstline += jump;
  • }
  • }
  • return (firstline);
  • }
  • void draw(int num, int taille)
  • {
  • int i;
  • int j;
  • int jump;
  • int blank;
  • int stars;
  • int hauteur_branche;
  • blank = last_line(taille) / 2 - first_line(num) / 2;
  • stars = first_line(num) - 1;
  • jump = 4;
  • hauteur_branche = num + 3;
  • for (i = 0; i < hauteur_branche; i++)
  • {
  • for (j = 0; j < blank; j++)
  • my_putchar(' ');
  • for (j = 0; j < stars; j++)
  • my_putchar('*');
  • blank--;
  • stars += 2;
  • my_putchar('*');
  • my_putchar('\n');
  • }
  • }
  • void draw_tronc(int taille)
  • {
  • int i;
  • int j;
  • int blank;
  • int largeur_tronc;
  • int hauteur_tronc;
  • if ((taille % 2) != 0)
  • largeur_tronc = taille;
  • else
  • largeur_tronc = taille + 1;
  • hauteur_tronc = taille;
  • blank = (last_line(taille) / 2) - (largeur_tronc / 2);
  • for (i = 0; i < hauteur_tronc; i++)
  • {
  • for (j = 0; j < blank; j++)
  • my_putchar(' ');
  • for (j = 0; j < largeur_tronc; j++)
  • my_putchar('|');
  • my_putchar('\n');
  • }
  • }
  • void sapin(int taille)
  • {
  • int i;
  • if (taille > 0)
  • {
  • i = 1;
  • while (i <= taille)
  • {
  • draw(i, taille);
  • i++;
  • }
  • draw_tronc(taille);
  • }
  • }
  • int trans(char *arg, int length)
  • {
  • int res;
  • int p;
  • res = 0;
  • p = 1;
  • res += (arg[(length--)] - '0');
  • while ((length >= 0) && (arg[length] != '-'))
  • {
  • p *= 10;
  • res += ((arg[length--] - '0') * p);
  • }
  • return (res);
  • }
  • int main(int argc, char **argv)
  • {
  • int length;
  • if (argc == 2)
  • {
  • length = 0;
  • while(argv[1][length] != 0)
  • length++;
  • length--;
  • sapin(trans(argv[1], length));
  • }
  • else
  • printf("Veuillez entrer la taille du sapin\n");
  • }
/*
** sapin.c for Sapin de Noel
** 
** Made by ali mdidech
** 
** 
** Started on  Sat Oct 11 14:19:02 2003 
** Last update Tue Oct 21 03:37:25 2003 
*/

#include <stdio.h>

void	my_putchar(char c)
{
  write(1, &c, 1);
}

int	last_line(int taille)
{
  int	i;
  int	jump;
  int	lastline;

  lastline = 7;
  jump = 6;
  for (i = 1; i < taille; i++)
    {
      if ((i % 2) != 0)
	lastline += jump;
      else if (i !=  1)
	{
	  jump += 2;
	  lastline += jump;
	}
    }
  return (lastline);
}

int	first_line(int taille)
{
  int	i;
  int	jump;
  int	firstline;

  firstline = 1;
  jump = 4;
  for (i = 1; i < taille; i++)
    {
      if ((i % 2) != 0)
	firstline += jump;
      else if (i !=  1)
	{
	  jump += 2;
	  firstline += jump;
	}
    }
  return (firstline);
}

void	draw(int num, int taille)
{
  int	i;
  int	j;
  int	jump;
  int	blank;
  int	stars;
  int	hauteur_branche;

  blank = last_line(taille) / 2 - first_line(num) / 2;
  stars = first_line(num) - 1;
  jump = 4;
  hauteur_branche = num + 3;
  for (i = 0; i < hauteur_branche; i++)
    {
      for (j = 0; j < blank; j++)
	my_putchar(' ');
      for (j = 0; j < stars; j++)
	my_putchar('*');
      blank--;
      stars += 2;
      my_putchar('*');
      my_putchar('\n');
    }
}

void	draw_tronc(int taille)
{
  int	i;
  int	j;
  int	blank;
  int	largeur_tronc;
  int	hauteur_tronc;

  if ((taille % 2) != 0)
    largeur_tronc = taille;
  else
    largeur_tronc = taille + 1;
  hauteur_tronc = taille;
  blank = (last_line(taille) / 2) - (largeur_tronc / 2);
  for (i = 0; i < hauteur_tronc; i++)
    {
      for (j = 0; j < blank; j++)
	my_putchar(' ');
      for (j = 0; j < largeur_tronc; j++)
	my_putchar('|');
      my_putchar('\n');
    }
}

void	sapin(int taille)
{
  int	i;

  if (taille > 0)
    {
      i = 1;
      while (i <= taille)
	{
	  draw(i, taille);
	  i++;
	}
      draw_tronc(taille);
    }
}

int	trans(char *arg, int length)
{
  int	res;
  int	p;

  res = 0;
  p = 1;
  res += (arg[(length--)] - '0');
  while ((length >= 0) && (arg[length] != '-'))
    {
      p *= 10;
      res += ((arg[length--] - '0') * p);
    }
  return (res);
}

int	main(int argc, char **argv)
{
  int	length;
  
  if (argc == 2)
    {
      length = 0;
      while(argv[1][length] != 0)
	length++;
      length--;
      sapin(trans(argv[1], length));
    }
  else
      printf("Veuillez entrer la taille du sapin\n");
}


 Conclusion

Tapez le nom du programme avec un entier en argument pour specifier la taille du sapin :)


 Sources du même auteur

LA COMMANDE CAT SANS LES OPTIONS
UN BEAU CARRE

 Sources de la même categorie

Source avec Zip KISIEL CD INFO DRIVE par kisiel0147852
Source avec une capture SUPPRESSION DES REDONDANCES DE FICHIERS par cyberntique
Source avec Zip ÉDITEUR DE RECTANGLES EN CONSOLE par seoseo
CONVERSION DE FICHIER EN FICHIER BMP par seoseo
Source avec Zip DETECTEUR EJP par idpro

Commentaires et avis

Commentaire de Irsla le 03/11/2003 10:02:13

ca va c'etait pas trop dur la piscine ? ;)
bon courage pour la bistro ;)lol

Commentaire de alimdi le 04/11/2003 02:04:20

Ca va je m'en suis pas trop mal sorti.. :)
Euhh la zeromatique je suis entrain, j'essayerais de la poster d'ailleurs :)

Commentaire de LordBob le 04/11/2003 21:17:53

une petite capture, non?

Commentaire de alimdi le 07/11/2003 03:44:48

Copie, compile, lance et tu verra le joli sapin :)

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,328 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales