Strona główna > Algorytm Euklidesa (NWD) > Rozszerzony algorytm euklidesa wyznaczania NWD

Rozszerzony algorytm euklidesa wyznaczania NWD

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int Algorytm_euklidesa(int a, int b)
{
    if(a>0 && b>0)
    {  int r=0;
       do{ r=a%b;
           a=b;
           b=r;
         }while(b!=0);
    return a;
    }
    return -1;
}

void Rozszerzony_Algorytm_Euklidesa(int a, int b)
{
    if(a>0 && b>0)
    {
       int a0=a, b0=b;
       int p=1, q=0, r=0, s=1;
       int c, quot, new_r, new_s;

       while (b!=0)
       {  c=a%b;
          quot =(int)floor(a/b);
          a=b;
          b=c;
          new_r=p-quot*r;
          new_s=q-quot*s;
          p=r; q=s;
          r=new_r;
          s=new_s;
       }
    printf("NWD(%d,%d)=%d*%d + %d*%d ", a0, b0, a0, p, b0, q);
    printf(" = %d\n", (a0*p)+(b0*q));
    }
    else printf("Error!");
 }

int main(int argc, char *argv[])
{
  int a,b;
  printf("Podaj a:  ");scanf("%d", &a);
  printf("Podaj b:  ");scanf("%d", &b);
  printf("NWD(%d,%d) = %d\n", a,b, Algorytm_euklidesa(a,b));
  printf("\nRozszerzony algorytm euklidesa:\n");
  Rozszerzony_Algorytm_Euklidesa(a,b);
  system("PAUSE");
  return 0;
}
  1. asdadsas
    17 Kwiecień 2013 o 2:08 pm

    w vc++ 2008 nie dziala (musialem dodac konwersje (double) argumentow funkcji floor

  2. 11 Czerwiec 2013 o 3:35 pm

    The person wanting to use weight training equipment
    and techniques could end up spending thousands on an at home system while the man with the need to just
    firm up his middle could spend next to nothing learning new floor
    exercises. Each exercise is comprised of 25 shorter moves that each take about 30 seconds to complete.

    Yoga is a great ab workout not only because of the physical exercise aspect, but
    also because it helps to calm your nerves and relieve stress.

  3. 27 Sierpień 2013 o 6:42 pm

    An impressive share! I’ve just forwarded this onto a friend who was doing a little homework on this.
    And he in fact ordered me breakfast due to
    the fact that I stumbled upon it for him… lol. So allow me to
    reword this…. Thanks for the meal!! But yeah, thanx for spending some time to discuss
    this topic here on your internet site.

  4. 7 Luty 2014 o 11:55 am

    Thanks for the good writeup. It in fact was a leisure account it.

    Glance complex to more introduced agreeable from you! However,
    how could we be in contact?

  5. info
    23 Marzec 2014 o 4:30 pm

    Today we can see around three hundred million tennis balls produced yearly.
    In the 4th and final cycle, take the dirt bike on a slow cruise.

    Paragliding appeals to people of all ages due to one main factor, the act of taking flight.

  6. 28 Marzec 2014 o 11:46 pm

    It is a good idea to change positions if you are not having luck in one area
    as it may change if you move someplace else. Before buying hunting supplies from a hunting store, you might want to use the following guidelines:
    . You may have heard of a break barrel air rifle, but you may not be aware of what one actually is.

  7. 26 Kwiecień 2014 o 1:51 am

    Good web site you have here.. It’s hard to find high-quality writing like yours nowadays.

    I honestly appreciate individuals like you!
    Take care!!

  8. 4 Maj 2014 o 4:14 am

    Hi there, just became alert to your blog through
    Google, and found that it’s truly informative.
    I’m going to watch out for brussels. I’ll be grateful if you continue this in future.
    A lot of people will be benefited from your writing.
    Cheers!

  9. 16 Maj 2014 o 3:25 pm

    Hey There. I discovered your blog using msn. This is a really neatly written article.

    I’ll be sure to bookmark it and return to learn extra of your useful info.
    Thank you for the post. I’ll definitely return.

  10. 18 Maj 2014 o 10:37 am

    It’s remarkable designed for me to have a site, which is valuable in support of my experience.

    thanks admin

  11. 3 Czerwiec 2014 o 1:18 pm

    You actually make it seem so easy with your presentation but I find this topic
    to be actually something which I think I would never understand.
    It seems too complex and very broad for me. I am looking forward
    for your next post, I’ll try to get the hang of it!

  12. 4 Czerwiec 2014 o 3:06 pm

    Thank you a lot for sharing this with all folks you really understand what you are speaking
    about! Bookmarked. Kindly also talk over with my site =). We will have a link change agreement between us

  13. 10 Czerwiec 2014 o 2:58 pm

    Hey There. I found your blog using msn. This is a really
    well written article. I’ll be sure to bookmark it and return to read more oof your useful information.
    Thanmks foor the post. I will certainly return.

  14. 18 Czerwiec 2014 o 6:24 am

    I like the helpful information you provide in your articles.

    I will bookmark your blog and check again here frequently.
    I’m quite certain I will learn a lot of new stuff right here!
    Good luck for the next!

  15. 24 Czerwiec 2014 o 8:54 pm

    Hi mates, nice article and good arguments commented here, I am genuinely enjoying by these.

  16. 17 Lipiec 2014 o 7:07 pm

    What a data of un-ambiguity and preserveness of precious know-how about unexpected feelings.

  17. 31 Lipiec 2014 o 11:24 am

    hello!,I really like your writing so much! proportion we be in contact more approximately your article on AOL?
    I require a specialist on this house to resolve my problem.
    May be that’s you! Taking a look ahead to peer you.

  18. 16 Sierpień 2014 o 8:10 am

    howdy! , Is extremely good writing really lots! amount many of us connect added concerning your posting on America online? My partner and i involve a specialist for this method to resolve the issue. May very well be that is people! Having a look onward to discover you actually.. Muscle Fitness And More

  19. 17 Sierpień 2014 o 11:12 pm

    Hi there to every body, it’s my first pay a quick visit of this webpage ( Donny – http://www.gaiaonline.com/journal/?mode=view&post_id=34898439&u=37166303 ); this web site consists of awesome and really excellent data in support of readers.

  20. 22 Sierpień 2014 o 5:35 pm

    I read this article fully about the resemblance of most up-to-date and preceding technologies,
    it’s amazing article.

  21. 14 Wrzesień 2014 o 8:32 am

    Heya i’m for tthe first time here. I found this board and
    I find It truly usefuil & it helped me out much. I hope
    to give something back and help others like you aided me.

  22. free (#
    15 Wrzesień 2014 o 6:44 pm

    This is the right webb sijte foor anyone who wants to understand
    thjs topic. You understand so much itts almoost tough to argu wit yyou
    (not tyat I personally will needd to…HaHa). You definitely putt a brand neew sppin on a sujbject that’s been discusssd for ages.
    Wonderful stuff, juhst great!

  1. No trackbacks yet.

Dodaj komentarz

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

Logo WordPress.com

Komentujesz korzystając z konta WordPress.com. Log Out / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Log Out / Zmień )

Facebook photo

Komentujesz korzystając z konta Facebook. Log Out / Zmień )

Google+ photo

Komentujesz korzystając z konta Google+. Log Out / Zmień )

Connecting to %s

Obserwuj

Otrzymuj każdy nowy wpis na swoją skrzynkę e-mail.

Dołącz do 47 obserwujących.

%d bloggers like this: