Représenter des nombres simples en format monétaire

Author:


{filelink=13385}

#include 

int main()
{
  float montants[3];
  long dollars[3];
  long centime[3];
  int i = 0;
  printf("Tapez 3 nombres séparés d'espace:");

  for(i = 0 ; i<3 ; i++)
    scanf("%f", &montants[i]);

  for(i = 0 ; i<3 ; i++)
  {
    dollars[i] = (long)montants[i];
    centime[i] = (long)(100.0*(montants[i]-dollars[i]));
  }

  printf("n");
  for(i = 0 ; i<3 ; i++)
  {
    printf("  $%d.%02d", dollars[i], centime[i]);
  }
  printf("");
  return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *