Jump to content
Keyloren

Numar de aparitii in sir

Recommended Posts

1.  Cerință:

 Se da un șir a cu n numere naturale, să se determine numărul de apariții a fiecărei cifre din șir și să se afiseze . Se va folosi oblicatoriu o funcție care determină numărul de apariții al fiecărei cifre și se va afișa. (Tip Void)

2. Rezolvare:

 

#include <iostream>
using namespace std;

void sir(int a[], int n)
{
    int i, j, nr = 0;
    for (j = 1; j <= 9; j++)
    {
        for (i = 1; i <= n; i++)
        {
            if (a[i] == j)
            {
                nr++;
            }
        }
        if (nr > 0)
        {
            cout << j << "se repeta de " << nr << "ori" << endl;
            nr = 0;
        }
    }
       
}

int main()
{
    int a[10], n, i, j;
    cin >> n;
    for (i = 1; i <= n; i++)
        cin >> a[i];
    sir(a, n);
    system("pause");
    return 0;
}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Who's Online   0 Members, 0 Anonymous, 2 Guests (See full list)

    There are no registered users currently online

×
×
  • Create New...

Important Information

This site uses cookies. By continuing browsing, you agree to the use of this information. For more details, see Terms of Use and Privacy Policy.