প্রবলেমটি পড়ুন এবং বুঝুন
#include<iostream>
using namespace std;
int happy(long long int a)
{
long long int sum=0;
int remain;
for(; a!=0;)
{
remain=a%10;
sum=sum+remain*remain;
a/=10;
}
if(sum<10)
{
if(sum==1)
return 1;
else
return 0;
}
happy(sum);
}
int main()
{
unsigned long long int test,i=0,a;
cin>>test;
int t;
while(test--)
{
i++;
cin>>a;
t=happy(a);
if(t==1)
cout<<"Case #"<<i<<": "<<a<<" is a Happy number."<<endl;
else
cout<<"Case #"<<i<<": "<<a<<" is an Unhappy number."<<endl;
}
return 0;
}
#include<iostream>
using namespace std;
int happy(long long int a)
{
long long int sum=0;
int remain;
for(; a!=0;)
{
remain=a%10;
sum=sum+remain*remain;
a/=10;
}
if(sum<10)
{
if(sum==1)
return 1;
else
return 0;
}
happy(sum);
}
int main()
{
unsigned long long int test,i=0,a;
cin>>test;
int t;
while(test--)
{
i++;
cin>>a;
t=happy(a);
if(t==1)
cout<<"Case #"<<i<<": "<<a<<" is a Happy number."<<endl;
else
cout<<"Case #"<<i<<": "<<a<<" is an Unhappy number."<<endl;
}
return 0;
}
No comments:
Post a Comment