Jump to content

Problema formare doua noi numere in C/C++


Florentin

Recommended Posts

Salutare ,sunt clasa a 10-a si de ceva timp ma tot chinui sa fac o problema.. Suna in felul urmator :

Se considera un numar natural n. Sa se formeze doua noi numere, unul format din cifrele pare ale lui n,celalalt format din cifrele impare. 

   Ex: n=13854 se va afisa 84 si 135

EDIT : Vreau sa mentionez ca nu as vrea totul mura-n gura.. As prefera niste sfaturi sau tema explicata in pseudocode. Multumesc anticipat.

Edited by Florentin
Link to comment
Share on other sites

  • Moderators

Poţi lua două numerele, nr1 şi nr2 iniţializate cu 0, la care adaugi la final cifrele lui n după caz (dacă e par merge în nr2 de exemplu, altfel în nr1). Cifrele introduse sunt în ordine inversă, deci va trebui să calculezi la sfârşit inversul ambelor numere.

O altă variantă (care nu necesită calculul inverselor) o poţi face studiind ce face următorul algoritm în pseudocod:

citeşte n
p ← 1
nr ← 0
cât timp n > 0 execută
	nr ← nr + p * (n mod 10)
	p ← p * 10
	n ← n div 10
sf_cât_timp
scrie nr

 

  • Upvote 2
Link to comment
Share on other sites

  • gaby changed the title to Problema formare doua noi numere in C/C++

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.

  • 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.