Advertisement
raisul82

LCM for all number incomplete

Nov 4th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdio.h>
  3. using namespace std;
  4. int main()
  5. {
  6. int remind,divisor,divident,i,j,n,temp,multip=1;
  7. printf("How many number you want to write : ");
  8. scanf("%d",&n);
  9. int A[n];
  10. int B[n];
  11. printf("Input your values\n");
  12. for(i=0; i<n; i++)
  13. {
  14. scanf("%d",&A[i]);
  15. B[i]=A[i];
  16. }
  17.  
  18. for(i=0; i<n; i++)
  19. {
  20. for(j=i+1; j<n; j++)
  21. {
  22. if(A[i]>A[j])
  23. {
  24. temp=A[i];
  25. A[i]=A[j];
  26. A[j]=temp;
  27. }
  28. }
  29. }
  30.  
  31. for(i=0; i<n-1; i++)
  32. {
  33. remind=1;
  34. divisor=A[i];
  35. //printf("%d ",divisor);
  36. divident=A[i+1];
  37. //printf("%d\n",divident);
  38.  
  39. while(remind!=0)
  40. {
  41. remind=divident%divisor;
  42. divident=divisor;
  43. divisor=remind;
  44. }
  45. A[i+1]=divident;
  46. }
  47.  
  48. printf("\nGCD = %d\n",divident);
  49.  
  50. for(i=0; i<n; i++)
  51. {
  52. multip=multip*B[i];
  53. }
  54. printf("LCM = %d\n\n",multip/divident);
  55.  
  56.  
  57.  
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement