numri_i_shifrave_te_perbashketa.txt

Shkarkuar 398 herë. Ngarkuar më Janar 2012

numri
i
shifrave
te
perbashketa
Shkarko Kthehu ne C++

	Zgjidhje   menyra 1 (me tabele)  :
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int nr1,n2,n1,shifra=0,perbashket=0,temp;
    cout<<"vendosni numrin e pare : ";
    cin>>nr1;
    n1=nr1;
    cout<<"vendosni numrin e dyte : ";
    cin>>n2;
    
    while(nr1>0){                                //nje cikel while per te gjetur numrin e shifrave 
         nr1=nr1/10;        
         shifra++;
                 }
    int tab[shifra];                             //deklarimi i tabeles             
    
    for(int i=0;i<shifra;i++){                   //inicializimi i tabeles me numrin e pare te ndare sipas shifrave
           tab[i]=n1%10;
           n1=n1/10;
                              }
    while(n2>0){                                //pjestojme numrin e dyte derisa te behet zero
       temp=n2%10;
       for(int j=0;j<shifra;j++){               //kontrollojme cdo shifer te tije nese eshte e barabarte me ndojnje pre j te parave  
          if(temp==tab[j])
             perbashket++;                       //nese po (++)
                                 }         
       n2=n2/10;                                 
                
                }                      
    cout<<"numra te perbashket : "<<perbashket;  //afishimi                        
    
    cin.get();
    cin.get();
    return EXIT_SUCCESS;
}

MENYRA 2 :
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int n1,n2,temp,perbashket=0,nr2;
    cout<<"vendosni numrin e pare : ";
    cin>>n1;
    cout<<"vendosni numrin e dyte : ";
    cin>>n2;
    
    nr2=n2;
    while(n1>0){
         temp=n1%10;
         while(n2>0){
              if(temp==n2%10)
                 perbashket++;       
                 n2=n2/10;    
                     }          
         n1=n1/10;           
         n2=nr2;           
                    }
    if(perbashket==0)
            cout<<"numrat qe vendoset nuk kane asnje shifer te perbashket \n";
    else