Example #1
1
File: c04.c Project: balanza/MenosC
int main()
{
  int x;
  int y;

  read(x);
  read(y);
  if (x < y) print(mcd(x,y));
  else print(mcd(y,x));
}
Example #2
0
int mcd(int a,int b)
{   
   if(a>b)
     return(mcd(a-b,b));
   else if(b>a)
     return(mcd(b-a,a));
   else if(a==b)
     return a;
}
Example #3
0
File: mcd.c Project: leolas95/c
int main(void)
{
        int a, b, c;

        printf("Ingresa los numeros:\n");
        scanf("%d%d%d", &a, &b, &c);

        printf("%d\n", mcd(a, mcd(b, c)));
        return 0;
}
Example #4
0
int mcd(int a, int b)
{
    while (a != b)
    {
        if (a > b)
        {
            return mcd(a - b, b);
        }
        else
        {
            return mcd(a, b - a);
        }
    }
    return a;
}
Example #5
0
int execute(int argc, char** argv) {

    if(argc < 0) {
        fprintf(stderr, "Erreur : pas assez d'argument dans la fonction d'execution\n");
        return 0;
    }

    if(strcmp(argv[0], "cd") == 0) {
        return mcd(argc, argv);

    } else if(strcmp(argv[0], "mkdir") == 0) {
        return mmkdir(argc, argv);

    } else if(strcmp(argv[0], "cat") == 0) {
        return mcat(argc, argv);

    } else if(strcmp(argv[0], "ls") == 0) {
        return mls(argc, argv);

    } else if(strcmp(argv[0], "vim") == 0) {
        return mvim(argc, argv);

    } else {
        printf("Commande non reconnu\n");
        return 0;
    }
}
Example #6
0
void mmPrintableBaseSpecificAccounts::getSpecificAccounts()
{
    wxArrayString* selections = new wxArrayString();
    wxArrayString accounts;
    for (const auto &account : Model_Account::instance().all(Model_Account::COL_ACCOUNTNAME))
    {
        if (Model_Account::type(account) == Model_Account::INVESTMENT) continue;
        accounts.Add(account.ACCOUNTNAME);
    }

    wxMultiChoiceDialog mcd(0, _("Choose Accounts"), reportName_, accounts);
    wxButton* ok = (wxButton*) mcd.FindWindow(wxID_OK);
    if (ok) ok->SetLabel(_("&OK "));
    wxButton* ca = (wxButton*) mcd.FindWindow(wxID_CANCEL);
    if (ca) ca->SetLabel(wxGetTranslation(g_CancelLabel));

    if (mcd.ShowModal() == wxID_OK)
    {
        wxArrayInt arraySel = mcd.GetSelections();

        for (size_t i = 0; i < arraySel.size(); ++i)
        {
            selections->Add(accounts.Item(arraySel[i]));
        }
    }

    accountArray_ = selections;
}
int mcd(int a,int b)
{
    if(b==0)
        return a;

    return mcd(b,a%b);
}
Example #8
0
int mcd(int dospri,int dosseg)
{
	if ((dospri%dosseg)==0)
		return dosseg;
	else
		return mcd(dosseg,dospri%dosseg);
}
// helper function
struct rational simplifyRational(struct rational r) {
    int d = mcd(r.numerator, r.denominator);
    if(d>1) {
        r.numerator = r.numerator/d;
        r.denominator = r.denominator/d;
    }
    return r;
}
Example #10
0
File: mcm.c Project: leolas95/c
int mcd(int a, int b)
{
        if (b == 0) {
                return a;
        } else {
                return mcd(b, a % b);
        }
}
Example #11
0
void simplifica (frac * c)
{
    int aux;

    aux = mcd (c->num, c->den);
    c->num /= aux;
    c->den /= aux;
}
Example #12
0
int main()
{
    int a, b, resultado;
 
    printf(" Ingresa dos numeros para encontrar el MCD:");
    scanf("%d%d", &a, &b);
    resultado = mcd(a, b);
    printf("El MCD  DE  %d y  %d es %d.\n", a, b, resultado);
}
Example #13
0
File: mcm.c Project: leolas95/c
int main(void)
{
        int a, b;

        printf("Ingresa los nĂºmeros:\n");
        scanf("%d%d", &a, &b);

        printf("mcm = %d\n", (a * b) / mcd(a, b));
        return 0;
}
Example #14
0
void Fraccion::simplifica()
{
    std::vector<int> v;
    v << _n << _d;
    const int Mcd = mcd(v);
    _n /= Mcd;
    _d /= Mcd;
    if (_d < 0)
        _d = -_d, _n = -_n;
}
bool sonPrimosRelativos(int n1, int n2){
  int a = mcd(n1,n2);
  bool b;
  if (a == 1){
    b = true;
  } else{
    b = false;
  }
  return b;
}
Example #16
0
int main()
{  
   int x,y,m;
   printf("x=");
   scanf("%d",&x);
   printf("y=");
   scanf("%d",&y);
   m=mcd(x,y);
   printf("MCD(%d %d)=%d\n",x,y,m);
   return 0;
}
Example #17
0
 main ()
{
int mcd (int,int);
int a,b;
clrscr();
printf("digite dos enteros que no sean primos \n");
scanf("%d%d",&a,&b);

printf("el minimo comun divisor entre %d y %d  es: %d ",a,b,mcd(a,b));
getch();
}
Racional::Racional(int num, int den)
{
	if (den<0)
	{
		den = -den;
		num = -num;
	}
	int div = mcd(abs(num), den);
	this->num = num/div;
	this->den = den/div;
}
int main()
{
    scanf("%d",&n);

    for(int i=1;i<n;i++)
        if(mcd(n,i)==1)
            c++;

    printf("%d\n",c);
    return 0;
}
Example #20
0
int mcd (int a, int b)
{
  if (a < 0)
    a = -a;
  if (b < 0)
    b = -b;

  a = a % b;
  if (a > 0)
    return mcd (b, a);
  else
    return b;
}
Example #21
0
int main()
{
	int n1,n2,n3,n4,dospri,dosseg;
	printf("Ingrese el primer numero: \n");
	scanf("%d",&n1);
	printf("\n");
	printf("Ingrese el segundo numero: \n");
	scanf("%d",&n2);
	printf("\n");	
	printf("Ingrese el tercer numero: \n");
	scanf("%d",&n3);
	printf("\n");	
	printf("Ingrese el cuarto numero: \n");
	scanf("%d",&n4);
	printf("\n");
	
	dospri=mcd(n1,n2);
	dosseg=mcd(dospri,n3);
	printf("el maximo comun divisor es:\n");
	printf("%d",mcd(dosseg,n4));
	return 0;

}
Example #22
0
void mmPrintableBase::accounts(int selection, wxString& name)
{
    if ((selection == 1) || (m_account_selection != selection))
    {
        m_account_selection = selection;
        if (accountArray_)
        {
            delete accountArray_;
            accountArray_ = nullptr;
        }

        switch (selection)
        {
        case 0: // All Accounts
            break;
        case 1: // Select Accounts
            {
                wxArrayString* accountSelections = new wxArrayString();
                Model_Account::Data_Set accounts = 
                    (m_only_active ? Model_Account::instance().find(Model_Account::ACCOUNTTYPE(Model_Account::all_type()[Model_Account::INVESTMENT], NOT_EQUAL), Model_Account::STATUS(Model_Account::OPEN))
                    : Model_Account::instance().find(Model_Account::ACCOUNTTYPE(Model_Account::all_type()[Model_Account::INVESTMENT], NOT_EQUAL)));
                std::stable_sort(accounts.begin(), accounts.end(), SorterByACCOUNTNAME());

                mmMultiChoiceDialog mcd(0, _("Choose Accounts"), m_title, accounts);

                if (mcd.ShowModal() == wxID_OK)
                {
                    for (const auto &i : mcd.GetSelections())
                        accountSelections->Add(accounts.at(i).ACCOUNTNAME);
                }

                accountArray_ = accountSelections;
            }
            break;
        default: // All of Account type
            {
                wxArrayString* accountSelections = new wxArrayString();
                auto accounts = Model_Account::instance().find(Model_Account::ACCOUNTTYPE(name));
                for (const auto &i : accounts)
                {
                    if (m_only_active && (i.STATUS == Model_Account::all_status()[Model_Account::CLOSED]))
                        continue;
                    accountSelections->Add(i.ACCOUNTNAME);
                }
                accountArray_ = accountSelections;
            }
        }
    }
}
template<int SizeAtCompileType> void mixingtypes(int size = SizeAtCompileType)
{
    typedef Matrix<float, SizeAtCompileType, SizeAtCompileType> Mat_f;
    typedef Matrix<double, SizeAtCompileType, SizeAtCompileType> Mat_d;
    typedef Matrix<std::complex<float>, SizeAtCompileType, SizeAtCompileType> Mat_cf;
    typedef Matrix<std::complex<double>, SizeAtCompileType, SizeAtCompileType> Mat_cd;
    typedef Matrix<float, SizeAtCompileType, 1> Vec_f;
    typedef Matrix<double, SizeAtCompileType, 1> Vec_d;
    typedef Matrix<std::complex<float>, SizeAtCompileType, 1> Vec_cf;
    typedef Matrix<std::complex<double>, SizeAtCompileType, 1> Vec_cd;

    Mat_f mf(size,size);
    Mat_d md(size,size);
    Mat_cf mcf(size,size);
    Mat_cd mcd(size,size);
    Vec_f vf(size,1);
    Vec_d vd(size,1);
    Vec_cf vcf(size,1);
    Vec_cd vcd(size,1);

    mf+mf;
    VERIFY_RAISES_ASSERT(mf+md);
    VERIFY_RAISES_ASSERT(mf+mcf);
    VERIFY_RAISES_ASSERT(vf=vd);
    VERIFY_RAISES_ASSERT(vf+=vd);
    VERIFY_RAISES_ASSERT(mcd=md);

    mf*mf;
    md*mcd;
    mcd*md;
    mf*vcf;
    mcf*vf;
    mcf *= mf;
    vcd = md*vcd;
    vcf = mcf*vf;
#if 0
    // these are know generating hard build errors in eigen3
    VERIFY_RAISES_ASSERT(mf*md);
    VERIFY_RAISES_ASSERT(mcf*mcd);
    VERIFY_RAISES_ASSERT(mcf*vcd);
    VERIFY_RAISES_ASSERT(vcf = mf*vf);

    vf.eigen2_dot(vf);
    VERIFY_RAISES_ASSERT(vd.eigen2_dot(vf));
    VERIFY_RAISES_ASSERT(vcf.eigen2_dot(vf)); // yeah eventually we should allow this but i'm too lazy to make that change now in Dot.h
    // especially as that might be rewritten as cwise product .sum() which would make that automatic.
#endif
}
void WaveformBlockFilterDesc::
        test()
{
    // It should instantiate CwtBlockFilter for different engines.
    {
        Heightmap::MergeChunkDesc::ptr mcd(new WaveformBlockFilterDesc);
        MergeChunk::ptr mc = mcd.read ()->createMergeChunk (0);

        EXCEPTION_ASSERT( !mc );

        Signal::ComputingCpu cpu;
        mc = mcd.read ()->createMergeChunk (&cpu);
        EXCEPTION_ASSERT( mc );
        EXCEPTION_ASSERT_EQUALS( vartype(*mc.get ()), "Heightmap::TfrMappings::WaveformBlockFilter" );

        Signal::ComputingCuda cuda;
        mc = mcd.read ()->createMergeChunk (&cuda);
        EXCEPTION_ASSERT( !mc );

        Signal::ComputingOpenCL opencl;
        mc = mcd.read ()->createMergeChunk (&opencl);
        EXCEPTION_ASSERT( !mc );
    }
}
	ENTERO racional_t::mcd(ENTERO e1, ENTERO e2)
	{
		if(e1==0) return e2;
		return mcd(e2%e1, e1);
	}
	ENTERO racional_t::mcm(ENTERO e1, ENTERO e2)
	{
		return (e1/mcd(e1, e2))*e2;
	}
	ENTERO mcd(ENTERO e1, ENTERO e2)
	{
		if(e1==0) return e2;
		return mcd(e2%e1, e1);
	}
Example #28
0
int main( int argc, char *argv[] )
{
    Scope global;

    Server s( "archiveopteryx", argc, argv );
    s.setup( Server::Report );

    bool security( Configuration::toggle( Configuration::Security ) );
    EString root( Configuration::text( Configuration::JailDir ) );

    if ( Configuration::toggle( Configuration::UseSmtp ) ||
            Configuration::toggle( Configuration::UseLmtp ) )
    {
        EString mc( Configuration::text( Configuration::MessageCopy ) );
        EString mcd( Configuration::text( Configuration::MessageCopyDir ) );
        if ( mc == "all" || mc == "errors" || mc == "delivered" ) {
            struct stat st;
            if ( mcd.isEmpty() )
                log( "message-copy-directory not set", Log::Disaster );
            else if ( ::stat( mcd.cstr(), &st ) < 0 || !S_ISDIR( st.st_mode ) )
                log( "Inaccessible message-copy-directory: " + mcd,
                     Log::Disaster );
            else if ( security && !mcd.startsWith( root ) )
                log( "message-copy-directory must be under jail directory " +
                     root, Log::Disaster );
        }
        else if ( mc == "none" ) {
            if ( Configuration::present( Configuration::MessageCopyDir ) )
                log( "Disregarding message-copy-directory (value " + mcd +
                     ") because message-copy is set to none " );
        }
        else {
            log( "Invalid value for message-copy: " + mc, Log::Disaster );
        }
    }


    EString sA( Configuration::text( Configuration::SmartHostAddress ) );
    uint sP( Configuration::scalar( Configuration::SmartHostPort ) );

    if ( Configuration::toggle( Configuration::UseSmtp ) &&
            Configuration::scalar( Configuration::SmtpPort ) == sP &&
            ( Configuration::text( Configuration::SmtpAddress ) == sA ||
              ( Configuration::text( Configuration::SmtpAddress ) == "" &&
                sA == "127.0.0.1" ) ) )
    {
        log( "smarthost-address/port are the same as smtp-address/port",
             Log::Disaster );
    }

    if ( Configuration::toggle( Configuration::UseLmtp ) &&
            Configuration::scalar( Configuration::LmtpPort ) == sP &&
            ( Configuration::text( Configuration::LmtpAddress ) == sA ||
              ( Configuration::text( Configuration::LmtpAddress ) == "" &&
                sA == "127.0.0.1" ) ) )
    {
        log( "smarthost-address/port are the same as lmtp-address/port",
             Log::Disaster );
    }

    if ( Configuration::toggle( Configuration::UseSmtpSubmit ) &&
            Configuration::scalar( Configuration::SmtpSubmitPort ) == sP &&
            ( Configuration::text( Configuration::SmtpSubmitAddress ) == sA ||
              ( Configuration::text( Configuration::SmtpSubmitAddress ) == "" &&
                sA == "127.0.0.1" ) ) )
    {
        log( "smarthost-address/port are the same as "
             "smtp-submit-address/port", Log::Disaster );
    }


    EString app =
        Configuration::text( Configuration::AllowPlaintextPasswords ).lower();
    if ( !( app == "always" || app == "never" ) )
        ::log( "Unknown value for allow-plaintext-passwords: " + app,
               Log::Disaster );
    if ( app == "never" &&
            Configuration::toggle( Configuration::UseTls ) == false &&
            Configuration::toggle( Configuration::AuthCramMd5 ) == false &&
            Configuration::toggle( Configuration::AuthDigestMd5 ) == false )
        ::log( "allow-plaintext-passwords is 'never' and use-tls is 'false', "
               "but only plaintext authentication mechanisms are allowed",
               Log::Disaster );

    EString apa =
        Configuration::text( Configuration::AllowPlaintextAccess ).lower();
    if ( !( apa == "always" || apa == "localhost" || apa == "never" ) )
        ::log( "Unknown value for allow-plaintext-access: " + apa,
               Log::Disaster );
    if ( apa == "never" &&
            Configuration::toggle( Configuration::UseTls ) == false )
        ::log( "allow-plaintext-access is 'never', but use-tls is 'false'",
               Log::Disaster );

    // set up an EGD server for openssl
    Entropy::setup();
    EString egd( root );
    if ( !egd.endsWith( "/" ) )
        egd.append( "/" );
    egd.append( "var/run/egd-pool" );
    (void)new Listener< EntropyProvider >( Endpoint( egd, 0 ), "EGD" );
    if ( !security ) {
        struct stat st;
        if ( stat( "/var/run/edg-pool", &st ) < 0 ) {
            log( "Security is disabled and /var/run/edg-pool does not exist. "
                 "Creating it just in case openssl wants to access it." );
            (void)new Listener< EntropyProvider >(
                Endpoint( "/var/run/edg-pool", 0 ), "EGD(/)" );
        }
    }
    if ( ::chmod( egd.cstr(), 0666 ) < 0 )
        log( "Could not grant r/w access to EGD socket", Log::Disaster );

    Listener< IMAP >::create(
        "IMAP", Configuration::toggle( Configuration::UseImap ),
        Configuration::ImapAddress, Configuration::ImapPort
    );
    Listener< IMAPS >::create(
        "IMAPS", Configuration::toggle( Configuration::UseImaps ),
        Configuration::ImapsAddress, Configuration::ImapsPort
    );
    Listener< POP >::create(
        "POP3", Configuration::toggle( Configuration::UsePop ),
        Configuration::PopAddress, Configuration::PopPort
    );
    Listener< POPS >::create(
        "POP3S", Configuration::toggle( Configuration::UsePops ),
        Configuration::PopsAddress, Configuration::PopsPort
    );
    Listener< ManageSieve >::create(
        "Sieve", Configuration::toggle( Configuration::UseSieve ),
        Configuration::ManageSieveAddress, Configuration::ManageSievePort
    );
    Listener< SMTP >::create(
        "SMTP", Configuration::toggle( Configuration::UseSmtp ),
        Configuration::SmtpAddress, Configuration::SmtpPort
    );
    Listener< LMTP >::create(
        "LMTP", Configuration::toggle( Configuration::UseLmtp ),
        Configuration::LmtpAddress, Configuration::LmtpPort
    );
    Listener< SMTPSubmit >::create(
        "SMTP-Submit", Configuration::toggle( Configuration::UseSmtpSubmit ),
        Configuration::SmtpSubmitAddress, Configuration::SmtpSubmitPort
    );
    Listener< SMTPS >::create(
        "SMTPS", Configuration::toggle( Configuration::UseSmtps ),
        Configuration::SmtpsAddress, Configuration::SmtpsPort
    );

    if ( Configuration::toggle( Configuration::UseTls ) ) {
        TlsThread::setup();
    }

    s.setup( Server::LogStartup );

    Listener< GraphDumper >::create(
        "Statistics", Configuration::toggle( Configuration::UseStatistics ),
        Configuration::StatisticsAddress, Configuration::StatisticsPort
    );

    EventLoop::global()->setMemoryUsage(
        1024 * 1024 * Configuration::scalar( Configuration::MemoryLimit ) );

    Database::setup();

    s.setup( Server::Finish );

    StartupWatcher * w = new StartupWatcher;

    Database::checkSchema( w );
    if ( security )
        Database::checkAccess( w );
    EventLoop::global()->setStartup( true );
    Mailbox::setup( w );

    SpoolManager::setup();
    Selector::setup();
    Flag::setup();
    IMAP::setup();

    if ( !security )
        (void)new ConnectionObliterator;

    s.run();
}
	ENTERO mcm(ENTERO e1, ENTERO e2)
	{
		return (e1/mcd(e1, e2))*e2;
	}
	racional_t::racional_t(ENTERO num, ENTERO den)
	{
		ENTERO aux = mcd(num,den);
		numerador_.modificar(num/aux);
		denominador_.modificar(den/aux);
	}