[ create a new paste ] login | about

Link: http://codepad.org/HJ5B5PcO    [ raw code | output | fork | 8 comments ]

C, pasted on Aug 23:
#include<stdio.h>
#include<conio.h>

int main()
{
	int a, b, i;

	do{
		printf("\nNhap vao so nguyen duong a = ");
		scanf_s("%4d", &a);
		if (a < 0)
		{
			printf("\nGia tri nhap vao khong hop le. Xin kiem tra lai !");
		}
	} while (a < 0);

	do{
		printf("\nNhap vao so nguyen duong b = ");
		scanf_s("%4d", &b);
		if (b < 0)
		{
			printf("\nGia tri nhap vao khong hop le. Xin kiem tra lai !");
		}
	} while (b < 0);

	int Max = a > b ? a : b;
	int Min = a < b ? a : b;
	if(a == b)
		return a;
	else
	{
		for(i = Max; i < a * b; i++)
			if(i % a == 0 && i % b == 0)
			{
				return i;
				break;
			}
	}
	printf("\nBCNN la %d", i);
	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by kid_banz on Oct 5
#include<stdio.h>
#include<conio.h>

int main()
{
int a, b,i=1;
printf("nhap a: ");
scanf_s("%d", &a);
printf("nhap b: ");
scanf_s("%d", &b);

for (i;i<=a*b; i++)
if (i%a == 0 && i%b == 0)
{
printf("%4d", i);
break;
}

_getch();

}
reply
posted by thinhdeptrai on Apr 25

reply
posted by thinhdeptrai on Apr 25
#include<bits/stdc++.h>
int main(){
int a,b,i;
do{
printf("nhap a=");
scanf("%d",&a);
if(a<=0){
printf("xin hay nhap lai");
}
}while(a<=0);
do{
printf("nhap b=");
scanf("%d",&b);
if(b<=0){
printf("xin hay nhap lai");
}}while(b<=0);
int max=a>b?a:b;
int min=a<b?a:b;
if(a==b)
return a;
else
for(i=max;i<a*b;i++)
if(i%a==0&&i%b==0){

break;}

printf("BCNN la %d",i);

return 0;
}
reply
posted by lethi200397 on Oct 20
#include<stdio.h>
#include<conio.h>
int main()
{
int i, a, b;
printf(" nhap a = ");
scanf("%d", &a);
printf(" nhap b = ");
scanf("%d", &b);
i = a;
do
{
if(i % a == 0 && i % b == 0)
{
printf(" UCNN = %d ", i);
break;
}
i++;
}
while(i <= a * b);
getch();
return 0;

}


reply
posted by 19127646 on Oct 27
#include <stdio.h>
int main()
{
int a,b;
int max = 0;
int i = 1;
scanf_s("%d %d", &a,&b);
while (i <= a)
{
if (a % i == 0 && b % i == 0)
max = i;
i++;
}
printf("%d", a*b/max);
return 0;
}
reply
posted by yonnon on Jul 12
#include<bits/stdc++.h>

using namespace std;
int main(){
int a;
int b;
cout <<"Enter your a: ";
cin >> a;
cout <<"Enter your b: ";
cin >> b;
if(a==b){
cout<<"BCNL= "<<a<<
endl;
return 0;
}
else if(a%b==0){
cout<<"BCNN= "<<a<<
endl;
return 0;
}
else if(b%a==0){
cout<<"BCNN= "<<b<<
endl;
return 0;
}
int temp=0;
int number=0;
number=a*b;
for(int i=number;i>=1;--i){
if(i%a==0 && i%b==0){
temp=i;
}
}
cout<<"BCNN= "<<temp<<
endl;
return 0;

}
reply
posted by luongphongnhan on Oct 22
#include<iostream>

using namespace std;
int checkBoiChung(int so1, int so2) {
int boiMax = 1;
int boiSo1;
int boiSo2;
if (so1 >= so2) {
for (int i = 1; i <= so2; i++)
{
boiSo1 = so1 * i;
for (int j = 1; j <= so1; j++)
{
boiSo2 = so2 * j;
if (boiSo1 ==boiSo2 ) {
return boiSo2;
}
}
}
}
else {
for (int i = 1; i <= so1; i++)
{
boiSo2 = so2 * i;
for (int j = 1; j <= so2; j++)
{
boiSo1 = so1 * j;
if (boiSo2 == boiSo1) {
return boiSo1;
}
}
}
}
}

int main() {
int a, b;
do
{
cout << "Moi nhap 2 so: ";
cin >> a >> b;
if (a <= 0 || b <= 0) {
cout << "Hai so nhap phai la so duong! Moi nhap lai" << endl;
}
} while (a<=0 || b<=0);
cout << "Gia tri boi chung lon nhat cua 2 so la: " << checkBoiChung(a, b) << endl;
system("pause");
return 0;
}
reply
posted by anhphuchdth321 on Feb 20
#include <iostream>
using namespace std;
int main()
{
int a, b,BCNN;
cout << "Enter a : ";
cin >> a;
cout << "Enter b : ";
cin >> b;

if (a == b) return a;
else {
for (int i = a*b;i >1;i--)
{
if (i % a == 0 && i % b == 0) BCNN= i;
}

}
cout << BCNN << endl;

return 0;
}
reply