9.11.14

Function : Excercise-4.2 : Check Whether the given number is Strange or Not.

[Use user defined function to solve this problem]

#include<iostream>
using namespace std;
int chkstrange(int digit);
int main()
{
int digit,p;
cout<<"Enter Number to Check: ";
cin>>digit;
p= chkstrange(digit);
if (p==1) cout<<"strange";
else
cout<<"Not strange";
}
//function start here
int chkstrange(int digit)
{
int temp,rem,temp2=1;
while(digit!=0)
{
temp=digit/10;
rem=digit%10;
digit=temp;
for(int i=2;i<rem;i++)
    {
    if (rem%i ==0)
    {
    temp2= 0;
    i=rem;
    }
    }   
}
return temp2;
}

19 comments:

  1. ID NO-201420406
    Batch-46th
    #include
    int main()
    {
    int num,i,f,r,sum=0,temp;

    cout << "Enter a number: ";
    cin >> num;

    temp=num;
    while(num)
    {
    i=1,f=1;
    r=num%10;

    while(i<=r){
    f=f*i;
    i++;
    }
    sum=sum+f;
    num=num/10;
    }
    if(sum==temp)
    cout << temp << " is a strange number";
    else
    cout << temp << " is not a strange number";

    return 0;
    }

    ReplyDelete
  2. Batch-46th
    Id:201420405

    #include
    using namespace std;
    int main()
    {
    int a,b,digit,p=1;
    cin>>digit;
    while(digit!=0)
    {
    a=digit/10;
    b=digit%10;
    cout<<b<<endl;
    digit=a;
    for(int i=2;i<b;i++)
    {
    if (b%i ==0)
    {
    p=0;
    i=b;
    }
    }
    }
    if (p==1) cout<<"strange";
    else
    cout<<"Not strange";
    }

    ReplyDelete
    Replies
    1. noted but answer is not relevant with question

      Delete
    2. Where is function ? read question carefully.

      Delete
  3. MD: Rashed Prodhania
    Batch-46th
    Id:201420763

    #include
    using namespace std;
    int main()
    {
    int L,M,digit,p=1;
    cin>>digit;
    while(digit!=0)
    {
    L=digit/10;
    M=digit%10;
    cout<<M<<endl;
    digit=L;
    for(int i=2;i<b;i++)
    {
    if (b%i ==0)
    {
    p=0;
    i=M;
    }
    }
    }
    //use if else statment
    if (p==1) cout<<"This is Strange";
    else
    cout<<"This is Not Strange";
    }

    ReplyDelete
  4. sir amr program half post hocche.plz do something

    ReplyDelete
    Replies
    1. There are some spam on your computer. Try using another browser or computer

      Delete
  5. Name-MainUddin
    ID-201421090
    Batch-46
    #include
    using namespace std;
    //base class
    class strange
    {
    public:
    void setdigit(int d)
    {
    digit=d;
    }
    protected:
    int digit;
    };
    //derived class
    class number : public strange
    {
    public:
    int i,j,t,d;
    int devide()
    {
    d=digit;
    while(d!=0)
    {
    j=d%10;
    d=d/10;
    for(i=2;i>a;
    nmb.setdigit(a);
    nmb.check();
    }

    ReplyDelete
  6. http://itlearn24.blogspot.com/2014/11/check-whether-given-number-is-strange.html

    ReplyDelete
  7. Name-Main Uddin
    ID-201421090
    Batch-46

    #include

    using namespace std;

    int StNumber ( int Num )
    {
    if ( Num > 2 )
    {
    for ( int L = 2 ; L <= ( Num/2 ) ; L++ )
    {
    if ( Num % L == 0 )
    return (0);
    }
    return (1);
    }
    }

    int main ()
    {
    int Num;
    cout<<"Enter The Number"<>Num;
    if ( StNumber ( Num ) )
    cout<<"Strange Number"<<endl;
    else
    cout<<"Not Strange Number"<<endl;
    cout<<endl;


    }

    ReplyDelete
  8. #include
    using namespace std;

    int strange(int digit)
    {
    int d,r;
    while(digit!=0)

    {
    d=digit/10;
    r=digit%10;
    digit=d;
    return r;
    }
    }

    int main()
    {
    int digit,p=1,re;
    cout<<"Enter number to check strange or not : ";
    cin>>digit;
    cout<<endl;
    re=strange(digit);
    for(int i=2;i<re;i++)
    {
    if (re%i ==0)
    {
    p=0;
    i=re;
    }
    }
    if (p==1)
    cout<<"Yes!!"<<endl<<"Enter number is strange number"<<endl<<endl;
    else
    cout<<"Not!!"<<endl<<"Enter number is not a strange number"<<endl;

    }

    ReplyDelete
  9. #include
    using namespace std;

    int strange(int digit)
    {
    int d,r;
    while(digit!=0)

    {
    d=digit/10;
    r=digit%10;
    digit=d;
    return r;
    }
    }

    int main()
    {
    int digit,p=1,re;
    cout<<"Enter number to check strange or not : ";
    cin>>digit;
    cout<<endl;
    re=strange(digit);
    for(int i=2;i<re;i++)
    {
    if (re%i ==0)
    {
    p=0;
    i=re;
    }
    }
    if (p==1)
    cout<<"Yes!!"<<endl<<"Enter number is strange number"<<endl<<endl;
    else
    cout<<"Not!!"<<endl<<"Enter number is not a strange number"<<endl;

    }

    ReplyDelete
  10. #include
    using namespace std;

    void strange(int i)
    {
    int check = 0, temp, rem;
    while (rem != 0){
    temp = i%10;
    rem = i/10;
    i = rem;
    for (int j = 2; j < temp; j++){
    if (temp%j==0){
    check = 1;
    break;
    }
    }
    }
    if (check == 1)
    cout << "This number is not a strange number.";
    else
    cout << "This is a strange number.";
    }

    int main()
    {
    int i;
    cout << "Enter number --: ";
    cin >> i;
    strange(i);
    return 0;
    }

    ReplyDelete

Comment Here