About Me

About Me : I have been working as a Software Engineer for various international companies for four years.Currently, I am working as a full stack Javascript developer in Petronas(Malaysia).

Skills

Skills • Javascript •Typescript •Python •C •Java •ReactJs • Redux • VueJs • NestJs • React Testing Library • Django• PostgreSQL • MySQL • NodeJs • Git • Docker • Jira • Visual Studio Code • Slack

সোমবার, ২৭ অক্টোবর, ২০১৪

UVA :10591 Happy Number

#include <iostream>
#include<cstring>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int re(long long  num)
{

    char ss[100];

    long long sum=0;
    sprintf(ss,"%lld",num);
    int len=strlen(ss);
    for(int i=0;i<len;i++)
    {
       int x=ss[i]-'0';
       sum+=x*x;
    }
   // cout<<sum<<endl;
    char chr[200];
    sprintf(chr,"%lld",sum);
    int l=strlen(chr);
    if(l==1)
    {
        return sum;
    }
    else return re(sum);



    }

int main()
{

    int test,cnt=0;
    scanf("%d",&test);
    while(test--)
    {
        long long  num;
        scanf("%lld",&num);
        int H=re(num);
        if(H==1)
        {
            printf("Case #%d: %lld is a Happy number.\n",++cnt,num);
        }
        else
        {
            printf("Case #%d: %lld is an Unhappy number.\n",++cnt,num);
        }




    }


    return 0;
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন