Facebook
From McHalt, 5 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 244
  1. #include <stdio.h>
  2.  
  3. int NWD(int a, int b){
  4.     int c;
  5.     for(;b != 0;){
  6.         c = a;
  7.         a = b;
  8.         b = c;
  9.         if(a == b) return a;
  10.         for(;a > b;){
  11.             a -= b;
  12.         }
  13.     }
  14.     return a;
  15. }
  16.  
  17. int main(){
  18.     int a,b;
  19.  
  20.     printf("Podaj a: ");
  21.     scanf("%d", &a);
  22.     printf("Podaj b: ");
  23.     scanf("%d", &b);
  24.  
  25.     if(a==b) printf("NWD: %d", a);
  26.     else if(a > b) printf("NWD: %d", NWD(b,a));
  27.     else printf("NWD: %d", NWD(a,b));
  28.  
  29.     return 0;
  30. }

Replies to NWD rss

Title Name Language When
NWD McHalt c 5 Years ago.