Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C by registered user nhannhan ( 5 years ago )
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <math.h>

void Input(int &n);
int SoChuSo(int n);
int Amstrong(int n, int scs);

int main(){
	int n;
	Input(n);
	int scs = SoChuSo(n);

	if(Amstrong(n, scs)){
		printf("%d la so Amstrong", n);
	}else{
		printf("%d khong phai la so Amstrong", n);
	}

	getch();
	return 0;
}

void Input(int &n){
	do{
		printf("Nhap n: ");
		scanf("%d", &n);

		if(n < 1){
			system("cls");
		}
	}while(n < 1);
}

int SoChuSo(int n){
	int scs = 1;
	while(n > 9){
		n /= 10;
		++scs;
	}

	return scs;
}

int Amstrong(int n, int scs){
	int temp = n;
	int tong = 0;
	
	while(temp){
		tong += (int) pow((double) (temp % 10), scs);
		temp /= 10;
	}

	if(tong == n){
		return 1;
	}else{
		return 0;
	}
}

 

Revise this Paste

Your Name: Code Language: