nhap so n tinh tong v chuyen tahnh so nt
#include<stdio.h>
#include<conio.h>
int tongchuso(long n)
{
int s=0, du;
while(n>0)
{
du=n%10;//du la so hang don vi
s=s+du;//cong so hang don vi vao s
n=n/10;//cat bo chu so hang con vi
}
return s;
}
void thuaso_nt(long n)
{
int i;
while(n>1)
{
for(i=2;i<=n;i++)//SO DAU TIEN N CHIA HET CHAC CHAN LA SO NGUYEN TO
{
if(n%i==0)
{
printf("%4d",i);
n=n/i;
break;//THOAT RA DE THUC HIEN KIEM TRA LAI TU 2
}
}
}
}
void main()
{
long n;
printf("
nhap n=");scanf("%ld",&n);
printf("
tong cac chu so cua n la %d
",tongchuso(n));
printf("
phan tich ra thua so nguyen to
");
thuaso_nt(n);
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top