3rd c++ Problem
Write a Program to check whether no is prime or not
without using
any /,% operator and If statement?
without using
any /,% operator and If statement?
Replies
-
Manish Goyal52 views but no replies...
Give it a try at least...
otherwise i will give you a clue -
gaurav.bhorkarPlease give a clue.
Maybe the problem should not allow use of Decision Control System and loops but allow use of %, /, *, etc. -
Sahithi PallaviPlease give us a clue goyal...!
-
Hussanal Farokeisdivis(a,b)
{
x=a;
while(x>b)
x-=b
a-b?return 0:return 1;
}
main:-
for(int j=2,jisdivis(number,j):{cout<<"prime";break;}:continue; -
Hussanal Faroke
may be there is some errors in extreme... take ur own modificationHussanal Farokeisdivis(a,b)
{
x=a;
while(x>b)
x-=b
b-x?return 0:return 1;
}
main:-
for(int j=2,jisdivis(number,j)?{cout<<"not prime";exit(0);}:continue;
cout<<"prime"; -
Manish GoyalGuys Hussanal Faroke gave you a great clue
yeah You can use ternary operator
Hussanal this statement ...seems to be illogical for meHussanal Farokeisdivis(number,j):{cout<<"prime";break;}:continue;
however nice attempt you are very close..I mean very much close
Good -
gaurav.bhorkarUse 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
Hey Gaurav My question was to check whether no is prime or not?gaurav.bhorkarUse 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;
}
Please read the Question before -
gaurav.bhorkar
char * array[] is the array of pointers to strings.gaurav.bhorkarUse 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;
}
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.bhorkarOh I am sorry!
I didn't read the question properly.
Sorry! -
Manish GoyalI 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 GoyalOkk 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;i 0) { 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.bhorkarOh! That was easy, wasn't that?
I was thinking too much. -
Manish Goyalyeah Garauv
It was easy..just you were to show some crazIness....
Anyhow..thanks for giving it a try -
Hussanal FarokeI don't know how to delete one post that is why i edited like this!!!!!!!!!!!!!!
-
aicbalint 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!