Replies
Welcome, guest
Join CrazyEngineers to reply, ask questions, and participate in conversations.
CrazyEngineers powered by Jatra Community Platform
-
@manish-r2Hoep • Dec 31, 2009
-
@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
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,j<number;j++)
isdivis(number,j)?{cout<<"not prime";exit(0);}:continue;
cout<<"prime"; -
@manish-r2Hoep • Jan 1, 2010
Guys 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 -
@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
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 -
@gauravbhorkar-Pf9kZD • Jan 1, 2010
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. -
@gauravbhorkar-Pf9kZD • Jan 1, 2010
-
@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
-
@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
-
@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-#