Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.15 KB | None | 0 0
  1. /*
  2.  *Christophe
  3.  *de Carvalho Pereira Martins
  4.  *2103
  5.  *creation : 09/11/10
  6.  *Dernière modif :
  7.  *Lire n, les n élément de va
  8.  *determinet K tel que
  9.  * k = -1 si ts les éléments de va valent 0
  10.  * k = indice du premier élément de va != 0
  11.  */
  12.  
  13. #define _CRT_SECURE_NO_WARNINGS
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. void main(void)
  19. {
  20.     short n=0,i=0,version,va[30],k=-1;
  21.     short *pVa,*pVaMax, *adresseI;
  22.    
  23.     do
  24.     {
  25.         printf("Quel version voulez vous utiliser ?\n 1 - normal\n2 - poiteur : ");
  26.         scanf("%hd",&version);
  27.     }while(version < 1 || version > 2);
  28.    
  29.     switch(version)
  30.     {
  31.         case 1:
  32.             @h@ /*initialisation taille du vecteur*/
  33.             @h@ do
  34.             @h@ {
  35.             @h@     printf("entrer la longueur du vecteur a remplir (1-30): ");
  36.             @h@     scanf("%hd",&n);
  37.             @h@ }while(n<1 || n > 30);
  38.  
  39.                 /*initialisation vecteur a */
  40.                 for(i=0;i<n;i++)
  41.                 {
  42.                     printf("nombre %hd : ",i+1);
  43.                     scanf("%ld",&va[i]);
  44.                 }
  45.                 /*affichage vecteur a */
  46.                 for(i=0;i<n;i++)
  47.                 {
  48.                     printf("%ld | ",va[i]);
  49.                 }
  50.                
  51.                 printf("\n");
  52.  
  53.                 /*analyse de va*/
  54.                 for(i=0 ; i<n ; i++)
  55.                 {
  56.                     if(va[i] != 0)
  57.                     {
  58.                         k = va[i];
  59.                         adresseI = &va[i];
  60.                         i = n;
  61.                     }
  62.                 }
  63.                
  64.                 printf("k = %ld\n",k);
  65.                 printf("adresse de l'indice = %hd\n",adresseI);
  66.             break;
  67.  
  68.         case 2 :
  69.                 /*initialisation taille du vecteur*/
  70.                 do
  71.                 {
  72.                     printf("entrer la longueur du vecteur a remplir (1-30): ");
  73.                     scanf("%hd",&n);
  74.                 }while(n<1 || n > 30);
  75.  
  76.                 /*initialisation vecteur a */
  77.                 for(pVa = va,pVaMax = pVa+n,i=1; pVa<pVaMax; pVa++,i++)
  78.                 {
  79.                     printf("nombre %hd : ",i);
  80.                     scanf("%ld",pVa);
  81.                 }
  82.                 /*affichage vecteur a */
  83.                 for(pVa = va,pVaMax = pVa+n; pVa<pVaMax; pVa++)
  84.                 {
  85.                     printf("%ld | ",*pVa);
  86.                 }
  87.                
  88.                 /*analyse de va*/
  89.                 for(pVa = va,pVaMax = pVa+n; pVa<pVaMax; pVa++)
  90.                 {
  91.                    
  92.                     if(*pVa != 0)
  93.                     {
  94.                         k = *pVa;
  95.                         adresseI = pVa;
  96.                         pVa += n;
  97.                     }
  98.                 }
  99.                
  100.                 printf("\nk = %ld\n",k);
  101.                 printf("\nadresse de l'indice = %hd\n",adresseI);
  102.             break;
  103.  
  104.         default : printf("erreur dans le choix de version\n");
  105.                 break;
  106.    
  107.     }
  108.    
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement