dimanche 24 octobre 2010

pair inpair.cpp

download : pair inpair.exe
#include<conio.h>
#include<stdio.h>
main()
{
      int t[100],pair[100],impair[100],i,n,imp,p,np,nimp;
      printf("entrez le nombre des entiers : ");
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
                       printf("entrez un entier : ");
                       scanf("%d",&t[i]);
                       }
                         p=0;
                         imp=0;
                         for(i=1;i<=n;i++)
                      {
                        if (t[i] % 2==0)
                        { p=p+1;
                                 pair[p]=t[i];
                       
                       }
                                      
                      
                                        else
                                          {
                                              imp=imp+1;
                                               impair[imp]=t[i] ;
                                           }}
                      
                                       
     
                                 for(i=1;i<=p;i++)
                               {  printf("le nombre pair est :%d \n ",pair[i]);}
                                 for(i=1;i<=imp;i++)
                                { printf("le nombre impair est : %d\n ",impair[i]);
                                 }
                                 getch();
                                 }      


Aucun commentaire:

Enregistrer un commentaire