Jump to content

Recommended Posts

  • Moderators
Posted

Sa se determine de cate ori apare un numar x intr-un vector.

Rezolvare:

#include<stdio.h>

 #include<conio.h>


 int v[30],n,nr,k;


 void citire(int &n)

 { FILE *f;

   f=fopen("fisier.txt", "rt");

   while(!feof(f))

     fscanf(f,"%d",&v[n++]);

   fclose(f);

 }


 int DI(int li, int ls)

 { int x, y;

   if (li<ls)

     { x = DI(li,(li+ls)/2);

       y = DI((li+ls)/2+1,ls);

     }

   else 

       if (v[li]==nr)

          k++;

   return k;

 }


 int main()

 { citire(n);

   nr=5;

   printf("Nr 5 apare de %d ori", DI(0,n-1));

   getch();

   return 0;

 }

sursa: tutorialehd.info

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.