3rd c++ Problem

Write a Program to check whether no is prime or not
without using
any /,% operator and If statement?

Replies

  • Manish Goyal
    Manish Goyal
    52 views but no replies...
    Give it a try at least...
    otherwise i will give you a clue
  • gaurav.bhorkar
    gaurav.bhorkar
    Please give a clue.
    Maybe the problem should not allow use of Decision Control System and loops but allow use of %, /, *, etc.
  • Sahithi Pallavi
    Sahithi Pallavi
    Please give us a clue goyal...!
  • Hussanal Faroke
    Hussanal Faroke
    isdivis(a,b)
    {
    x=a;
    while(x>b)
    x-=b
    a-b?return 0:return 1;
    }
    main:-
    for(int j=2,j isdivis(number,j):{cout<<"prime";break;}:continue;
  • Hussanal Faroke
    Hussanal Faroke
    Hussanal Faroke
    isdivis(a,b)
    {
    x=a;
    while(x>b)
    x-=b
    b-x?return 0:return 1;
    }
    main:-
    for(int j=2,j isdivis(number,j)?{cout<<"not prime";exit(0);}:continue;
    cout<<"prime";
    may be there is some errors in extreme... take ur own modification
  • Manish Goyal
    Manish Goyal
    Guys Hussanal Faroke gave you a great clue
    yeah You can use ternary operator
    Hussanal Faroke
    isdivis(number,j):{cout<<"prime";break;}:continue;
    Hussanal this statement ...seems to be illogical for me
    however nice attempt you are very close..I mean very much close
    Good
  • gaurav.bhorkar
    gaurav.bhorkar
    Use a loop to check the condition and goto to jump.

    int main ()
    {
    int num ;
    char * array[] = {"even", "odd"} ;
    printf ("Enter any num") ;
    scanf ("%d", &num) ;
    while (num)
    {
    while (num == 1)
    goto label1;
    num -= 2 ;
    }
    label1 : printf ("The number is %s", array[num]) ;
    return 0;
    }
  • Manish Goyal
    Manish Goyal
    gaurav.bhorkar
    Use a loop to check the condition and goto to jump.

    int main ()
    {
    int num ;
    char * array[] = {"even", "odd"} ;
    printf ("Enter any num") ;
    scanf ("%d", &num) ;
    while (num)
    {
    while (num == 1)
    goto label1;
    num -= 2 ;
    }
    label1 : printf ("The number is %s", array[num]) ;
    return 0;
    }
    Hey Gaurav My question was to check whether no is prime or not?
    Please read the Question before
  • gaurav.bhorkar
    gaurav.bhorkar
    gaurav.bhorkar
    Use a loop to check the condition and goto to jump.

    int main ()
    {
    int num ;
    char * array[] = {"even", "odd"} ;
    printf ("Enter any num") ;
    scanf ("%d", &num) ;
    while (num)
    {
    while (num == 1)
    goto label1;
    num -= 2 ;
    }
    label1 : printf ("The number is %s", array[num]) ;
    return 0;
    }
    char * array[] is the array of pointers to strings.

    printf ("The number is %s", array[num]) ;
    When value of num is 0, it prints "even" because the string "even" is present at position 0 in the array.
  • gaurav.bhorkar
    gaurav.bhorkar
    Oh I am sorry!

    I didn't read the question properly.

    Sorry!
  • Manish Goyal
    Manish Goyal
    I agree with you but that is fine for checking whether no is even or odd
    absolutely correct No doubt

    But I want to check whether no is prime or not...
    I hope you got it

    for eg

    Please enter no
    20
    sory not a prime no

    Please enter no

    3
    Yes it is a prime no

    Take it easy dude.....The clue is already given....
  • Manish Goyal
    Manish Goyal
    Okk Guys ...I think now i should give you the code ...
    so here it is
    #include
    #include
    int main()
    {
    int i,no,a,b;
    cout<<"Enter any no"<>no;
    a=no;
    for(i=2;i0)
        {
            no=no-i;
        }
        b=(no==0)?-1:1;
        (b==1)?(no=a):(i=no);
    }
    (b!=-1&no!=1)?cout<<"Prime no":cout<<"Not a prime no";
    getch();
    return 0;
    }
    
  • gaurav.bhorkar
    gaurav.bhorkar
    Oh! That was easy, wasn't that?

    I was thinking too much.
  • Manish Goyal
    Manish Goyal
    yeah Garauv
    It was easy..just you were to show some crazIness....
    Anyhow..thanks for giving it a try
  • Hussanal Faroke
    Hussanal Faroke
    I don't know how to delete one post that is why i edited like this!!!!!!!!!!!!!!

  • aicbal
    aicbal
    int main()
    {
    int num,i,j,flag=FALSE;
    printf("Enter a number: ");
    scanf("%d",&num);
    for(i=2;i {
    j=num/i;
    j=0?flag=TRUE:;
    }
    flag=TRUE?printf("Not Prime");printf("Prime");
    }


    #-Link-Snipped-#

You are reading an archived discussion.

Related Posts

If anyone wants to share with us your lovely memories of 2009 then post it here
I hope most of you Guys have faced this attack many times but don't know about it ie phishing attack Phishing is a form of social engineering. Phishing attacks use...
Bangalore: Quit smoking and get a 10 percent hike in basic pay. That is the offer made by the head of a Bangalore based firm to coax his colleagues to...
Quick Heal CEan of the month December 2009 is... 😁CEan - Goyal420😁 ​ CEan Goyal420 joined CE in September 2009 and has been an exceptional contributor to CE. Goyal420 belongs...
Official Announcement: https://www.crazyengineers.com/forum/announcements/31251-quick-heal-cean-month-december-2009-a.html Congratulations, Goyal420! Keep up the excellent work!