Replies
Welcome, guest
Join CrazyEngineers to reply, ask questions, and participate in conversations.
CrazyEngineers powered by Jatra Community Platform
-
@manish-r2Hoep • Dec 31, 2009
52 views but no replies...
Give it a try at least...
otherwise i will give you a clue -
@gauravbhorkar-Pf9kZD • Dec 31, 2009
Please give a clue.
Maybe the problem should not allow use of Decision Control System and loops but allow use of %, /, *, etc. -
@sahithi-oJZaYj • Dec 31, 2009
Please give us a clue goyal...!
-
@hussanal-faroke-U5nNM8 • Dec 31, 2009
isdivis(a,b)
{
x=a;
while(x>b)
x-=b
a-b?return 0:return 1;
}
main:-
for(int j=2,j<number;j++)
isdivis(number,j):{cout<<"prime";break;}:continue; -
@hussanal-faroke-U5nNM8 • Dec 31, 2009
Hussanal Farokeisdivis(a,b)
{
x=a;
while(x>b)
x-=b
b-x?return 0:return 1;
}
main:-
for(int j=2,j<number;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-r2Hoep • Jan 1, 2010
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 -
@gauravbhorkar-Pf9kZD • Jan 1, 2010
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-r2Hoep • Jan 1, 2010
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;
}Hey Gaurav My question was to check whether no is prime or not?
Please read the Question before -
@gauravbhorkar-Pf9kZD • Jan 1, 2010
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;
}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.
-
@gauravbhorkar-Pf9kZD • Jan 1, 2010
Oh I am sorry!
I didn't read the question properly.
Sorry! -
@manish-r2Hoep • Jan 1, 2010
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-r2Hoep • Jan 2, 2010
Okk Guys ...I think now i should give you the code ...
so here it is
#include<iostream.h> #include<conio.h> int main() { int i,no,a,b; cout<<"Enter any no"<<endl; cin>>no; a=no; for(i=2;i<no;i++) { while(no>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; } -
@gauravbhorkar-Pf9kZD • Jan 2, 2010
Oh! That was easy, wasn't that?
I was thinking too much. -
@manish-r2Hoep • Jan 2, 2010
yeah Garauv
It was easy..just you were to show some crazIness....
Anyhow..thanks for giving it a try -
@hussanal-faroke-U5nNM8 • Mar 15, 2011
I don't know how to delete one post that is why i edited like this!!!!!!!!!!!!!!
-
@aicbal-t5T7aK • Mar 25, 2011
int main()
{
int num,i,j,flag=FALSE;
printf("Enter a number: ");
scanf("%d",&num);
for(i=2;i<num;i++)
{
j=num/i;
j=0?flag=TRUE:;
}
flag=TRUE?printf("Not Prime");printf("Prime");
}
#-Link-Snipped-#