dimanche 5 avril 2020

The Lucky Number

Sereen loves numbers very much. She believes that some numbers are lucky numbers based on some relation between its digits or value. Every day she makes new lucky numbers rule.

Today's rule is that: a given number will be lucky if the sum of the value of its even digits is divisible by 4.

For Example, 261 is a lucky number because 2+6=8, 8 is divisibly 4, however, 121 is not a lucky number because 2 is not divisible on 4.

Write a program for this!

#include<iostream>
using namespace std;
int main() {
int lucky{0};
int sum{0};
int sum_odd{0};
int digit{0};
int odd{0};
cin>>lucky;
  if((lucky/100%10)==0){
    lucky=lucky*10;
  }
for(int i=10;lucky>i;i=i*10){
  digit++;
  if((lucky/i%10)%2==0){
    sum=sum+(lucky/i%10);
  }
  else if((lucky/i%10)%2!=0){
    sum_odd=sum_odd+(lucky/i%10);
    odd++;
  }
}
  if(sum%4==0){
    cout<<lucky<<" is a lucky number, sum = "<<sum<<endl;
  }
  if(sum%4!=0){
    cout<<lucky<<" is not a lucky number, sum = "<<sum<<endl;
  }
   if(digit==odd){
    cout<<lucky<<" is not a lucky number, sum = "<<sum_odd<<endl;
  }
 return 0;
}

there is a bugs and I cant detect where some test case execute and some not can any one help me to fix it or give right code to this program and thanx

Aucun commentaire:

Enregistrer un commentaire