Results 1 to 3 of 3

Thread: [C++] -

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Dec:2013
    Location: Bulgaria
    Posts: 2

    [C++] -

    . - . (0-9), , , - . main() . ?

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    #define N 30
    int A[N], n, i, j=0, v=0;
    
    void inputkeyboard()
    {
        do
     {
         cout<<"\n Razmer na masiva: ";
         cin>>n;
     }
     while (n<0 || n>N);
    
        for (i=0; i<n; i++)
        {
          cout<<"\n A["<<i+1<<"] = ";
          do
          {
            cin>>A[i];
          }
          while (A[i]<100 || A[i]>999);
        }
    }
    
    void inputrandom()
    {
        srand(time(0));
           do
     {
         cout<<"\n Razmer na masiva: ";
         cin>>n;
     }
     while (n<0 || n>N);
    
        for (i=0;i<n;i++)
        {
        A[i] = rand()%(999-100+1)+100;
        }
    
        for (i=0;i<n;i++)
        {
            cout<<"\n A["<<i+1<<"] = "<<A[i];
        }
    }
    
    int main()
    {
        inputrandom();
        int E[90], D[90], S[90], T[90], max=0; //edinici, desetici, stotici, temp
        int P[10] = {};
        for (i=0;i<n;i++,j++)
        {
            E[j]=A[i]%10;
            T[j]=A[i]/10;
            D[j]=T[j]%10;
            S[j]=T[j]/10;
        }
    
       for (j=0;j<n;j++)
       {
           if (E[j]==0) P[0]++; if (D[j]==0) P[0]++; if (S[j]==0) P[0]++;
           if (E[j]==1) P[1]++; if (D[j]==1) P[1]++; if (S[j]==1) P[1]++;
           if (E[j]==2) P[2]++; if (D[j]==2) P[2]++; if (S[j]==2) P[2]++;
           if (E[j]==3) P[3]++; if (D[j]==3) P[3]++; if (S[j]==3) P[3]++;
           if (E[j]==4) P[4]++; if (D[j]==4) P[4]++; if (S[j]==4) P[4]++;
           if (E[j]==5) P[5]++; if (D[j]==5) P[5]++; if (S[j]==5) P[5]++;
           if (E[j]==6) P[6]++; if (D[j]==6) P[6]++; if (S[j]==6) P[6]++;
           if (E[j]==7) P[7]++; if (D[j]==7) P[7]++; if (S[j]==7) P[7]++;
           if (E[j]==8) P[8]++; if (D[j]==8) P[8]++; if (S[j]==8) P[8]++;
           if (E[j]==9) P[9]++; if (D[j]==9) P[9]++; if (S[j]==9) P[9]++;
       }
    
      for (v=0;v<10;v++)
       {
        if (P[v]>max)
        max=P[v];
       }
    
       if (max=P[0]) cout<<"\n Nai-chesto sreshtanata cifra e 0.";
       if (max=P[1]) cout<<"\n Nai-chesto sreshtanata cifra e 1.";
       if (max=P[2]) cout<<"\n Nai-chesto sreshtanata cifra e 2.";
       if (max=P[3]) cout<<"\n Nai-chesto sreshtanata cifra e 3.";
       if (max=P[4]) cout<<"\n Nai-chesto sreshtanata cifra e 4.";
       if (max=P[5]) cout<<"\n Nai-chesto sreshtanata cifra e 5.";
       if (max=P[6]) cout<<"\n Nai-chesto sreshtanata cifra e 6.";
       if (max=P[7]) cout<<"\n Nai-chesto sreshtanata cifra e 7.";
       if (max=P[8]) cout<<"\n Nai-chesto sreshtanata cifra e 8.";
       if (max=P[9]) cout<<"\n Nai-chesto sreshtanata cifra e 9.";
    
        return 0;
    }

  2. #2
    Registered User ined's Avatar
    Join Date: Nov:2006
    Location: Varna
    Posts: 1,078
    if == , = .

    .
    , - main() :

    Code:
    int main()
    {
        inputrandom();
        int P[10] = {};
        int p, max;
        
        for (i=0;i<n;i++)
        {
            P[A[i]%10]++;
            p= A[i]/10;
            P[p%10]++;
            P[p/10]++;
        }
    
       
        max = -1;
        for (i=0;i<10; i++) 
            if (P[i]>max) 
                max=P[i];
        
        for (i=0; i<10; i++)
            if (P[i]==max) 
                cout <<"\n Nai-chesto sreshtanata cifra e " << i << "  " << max << " broia\n";
            
        system("pause");
        return 0;
    }
    Last edited by ined; 16th December 2013 at 11:47.
    ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
    Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173

  3. #3
    Registered User
    Join Date: Dec:2013
    Location: Bulgaria
    Posts: 2
    , . .

    , . , .
    Last edited by Spydoc; 16th December 2013 at 12:04.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |