Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* So hua hon la hai so nguyen duong sao cho:
- Tong cac uoc duong (khong tinh so do) = So con lai + 1
- VA NGUOC LAI. Vi du: 48, 75 */
- #include<conio.h>
- #include<stdio.h>
- int sohuahon(int n1, int n2)
- {
- int sum1=0,sum2=0;
- int i=1,j=1;
- for(i;i<=n1/2;i++)
- {
- if(n1%i==0) sum1+=i;
- }
- for(j;j<=n2/2;j++)
- {
- if(n2%j==0) sum2+=j;
- }
- printf("\n%d\n",sum1);
- printf("%d\n",sum2);
- if((sum1-1==n2)&&(sum2-1==n1)) return 1;
- else return 0;
- }
- int main()
- {
- int M;
- printf("Nhap vao M\n");
- do
- {
- scanf("%d",&M);
- if((M<=1)||(M>=2000)) printf("Nhap M loi, NHAP LAI!\n");
- }
- while((M<=1)||(M>=2000));
- int N;
- printf("Nhap vao N\n");
- do
- {
- scanf("%d",&N);
- if((N<=1)||(N>=2000)) printf("Nhap N loi, NHAP LAI!\n");
- }
- while((N<=1)||(N>=2000));
- if(sohuahon(M,N)) printf("Hai so ban da nhap la cap so hua hon!");
- else printf("Hai so ban da nhap khong phai la cap so hua hon!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement