Skip to content

Instantly share code, notes, and snippets.

@Hajto
Last active November 29, 2016 13:45
Show Gist options
  • Save Hajto/d12abbffb7a01f8c57981cabb0f7179d to your computer and use it in GitHub Desktop.
Save Hajto/d12abbffb7a01f8c57981cabb0f7179d to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int NWD(int x, int y) {
int z;
while (y != 0) {
z = x % y;
x = y;
y = z;
}
return x;
}
void swap(int *a, int *b){
int temp = *b;
*b = *a;
*a = temp;
}
int main() {
int a, b;
printf("Programem tym mozesz obliczyc NWD \n");
printf("------------------------------------------\n \n");
printf("Podaj pierwsza liczbe: ");
scanf("%d", &a);
printf("Podaj druga liczbe: ");
scanf("%d", &b);
if(a < b) {
swap(a,b);
}
/*
if (a > b) {
a = x;
b = y;
} else {
b = x;
a = y;
}; */
printf("\n %d %d \n", a,b);
int n = NWD(a, b);
printf("NWD wynosi : %d", n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment