Function Programming : Strange Number in C

WAP to check whether the given input is Strange or Not.

#include<stdio.h>
int main()
{
int digit;
scanf("%d", &digit);
strng(digit);
}

int strng(int d)
{
int i, j, t=1;
while (d!=0)
{
j=d%10;
d=d/10;
for (i=2; i<j; i++)
{
if ( j%i = =0 )
{
t=0;
break;
}
}
}

if (t = = 1)
printf("\nThis number is strange");
else
printf("\nThis number is not strange");
}

1. //#include
main()
{
int digit;
scanf("%d",&digit);
strng(digit);
}
int strng(int d)
{
int i,j,t=1;
while(d!=0)
{
j=d%10;
d=d/10;
for(i=2;i<j;i++)
{
if(j%i==0)
{
t=0;
break;
}
}
}
if(t==1)
printf("this number is strange");
else
printf("this number is not strange");
}

2. //#include
main()
{
int digit;
scanf("%d",&digit);
strng(digit);
}
int strng(int d)
{
int i,j,t=1;
while(d!=0)
{
j=d%10;
d=d/10;
for(i=2;i<j;i++)
{
if(j%i==0)
{
t=0;
break;
}
}
}
if(t==1)
printf("this number is strange");
else
printf("this number is not strange");
}

3. #include
main()
{
int j;
scanf("%d",&j);
strange (j);
}

int strange (int a)
{
int i,p,q,temp;
while(a!=0)
{
p=a%10;
a=a/10;
q=p;

for (i=2;i<q;i++)
{
if(q%i==0)
{
temp=0;
break;
}
}
}
if(temp==0)
printf(" not strange number ");
else
printf(" strange number ");
}

4. #include
int strange(int digit);
main()
{
int digit;
printf("Given an input to check a strange number: ");
scanf("%d",&digit);
strange(digit);
}
int strange(int d)

{
int i,rem,flag=1;
while(d!=0)
{
rem=d%10;
d=d/10;
for(i=2;i<rem;i++)
{

if(rem%i==0)
{
flag=0;
break;
}
}
}
if(flag==1)
printf("\nGiven input is a strange number");
else
printf("\nGiven input is not a strange number");
}

5. #include
#include

int check_strange(int);
int main()
{
int a,rem;
printf("\n Enter number for check if it is strange or not; ");
scanf("%d",a);
rem=check_strange(a);
getch();
return 0;

}

int check_strange(int b)
{
int i,n,st=1;
while(b!=0)
{
n=b%10;
b/=10;
for(i=2;i<n;i++)
{
if(n%i==0)
{
st=0;
break;

}

}
if(st==1)
printf("\n This is strange number",st);
else
printf("\n This is not strange number",st);

return st;
}

}

6. This comment has been removed by the author.

7. #include
#include
int perfect_check(int);
int main()
{
int n,shohan;
printf("\n Enter number for check weathe it is perfect or not:");
scanf("%d",&n);
shohan=perfect_check(n);
getch();
return 0;

}

int perfect_check(int salmaan)
{
for(shuvo=1;shuvo<salmaan;shuvo++)
{
if(salmaan%shuvo==0)
}
printf("\n It is perfect number");
else
printf("\n It is not perfect number");
getch();
return shuvo;

}

8. #include
#include
int check_strange(int);
int main()
{
int j,shohan;
printf("\n Enter number for check if it is strange or not : ");
scanf("%d",&j);
shohan=check_strange(j);
getch();
return 0;

}

int check_strange(int n)
{
int i,result,st=1;
while(n!=0)
{
result=n%10;
n/=10;
i=2;
do
{
if(result%i==0)
{
st=0;
break;
}
i++;
}while(i<result);

if(st==1)
printf("\n This is strange number",st);
else
printf("\n This is not strange number",st);
return st;
}

}

9. #include
#include
int check_strange(int);
int main()
{
int n,shohan;
printf("\n Enter number for check if it is strange or not : ");
scanf("%d",&n);
shohan=check_strange(n);
getch();
return 0;

}

int check_strange(int a)
{
while(a!=0)
{
a/=10;
i=2;
{
{
st=0;
break;

}
i++;
}

if(st==1)
printf("\n This is strange number",st);
else
printf("\n This is not strange number",st);
return st;
}

}

10. Md. Rajib Sarker Id: 201320635December 12, 2013 at 10:32 PM

#include
main()
{
int j;
scanf("%d",&j);
strange (j);
}

int strange (int a)
{
int i,p,q,temp;
while(a!=0)
{
p=a%10;
a=a/10;
q=p;

for (i=2;i<q;i++)
{
if(q%i==0)
{
temp=0;
break;
}
}
}
if(temp==0)
printf(" not strange number ");
else
printf(" strange number ");
}

11. Md. Rajib Sarker Id: 201320635December 12, 2013 at 10:32 PM

#include
main()
{
int j;
scanf("%d",&j);
strange (j);
}

int strange (int a)
{
int i,p,q,temp;
while(a!=0)
{
p=a%10;
a=a/10;
q=p;

for (i=2;i<q;i++)
{
if(q%i==0)
{
temp=0;
break;
}
}
}
if(temp==0)
printf(" not strange number ");
else
printf(" strange number ");
}

12. Md. Rajib Sarker Id: 201320635December 12, 2013 at 10:32 PM

#include
main()
{
int j;
scanf("%d",&j);
strange (j);
}

int strange (int a)
{
int i,p,q,temp;
while(a!=0)
{
p=a%10;
a=a/10;
q=p;

for (i=2;i<q;i++)
{
if(q%i==0)
{
temp=0;
break;
}
}
}
if(temp==0)
printf(" not strange number ");
else
printf(" strange number ");
}

13. Md. Rajib Sarker Id: 201320635December 12, 2013 at 10:33 PM

//#include
main()
{
int digit;
scanf("%d",&digit);
strng(digit);
}
int strng(int d)
{
int i,j,t=1;
while(d!=0)
{
j=d%10;
d=d/10;
for(i=2;i<j;i++)
{
if(j%i==0)
{
t=0;
break;
}
}
}
if(t==1)
printf("this number is strange");
else
printf("this number is not strange");
}

14. #include
#include
int funcx(int);
int main()
{
int n,result;
scanf("%d",&n);
result=funcx(n);
getch();
return 0;
}

int funcx(int digit)
{
int i,st=1,rem;
while(digit!=0)
{
rem=digit%10;
digit/10;
for(i=0;i<rem;i++)
{
if(rem%2==0)
{
st=0;
break;
}

}
if(st==1)
printf("\n It is a strange number:");
else
printf("\n It is not a strange number:");
return st;
}

}

15. #include
//#include
#include
void main()
{
char str1[25],str2[25];
int dif;
//clrscr();
printf("Enter the string to check the String is True or not: ");
gets(str1);
strcpy(str2,str1);
strrev(str2);
dif=strcmp(str1,str2);
if(dif==0)
printf("\n%s is True",str1);
else
printf("\n%s is not True\n",str1);
}

16. #include
int checkStrange(int n)
{
int i,p,q,temp;
while(n!=0)
{
p=n%10;
n=n/10;
q=p;

for (i=2; i<q; i++)
{
if(q%i==0)
{
temp=0;
break;
}
}
}
return temp;
}
int main()
{
int n,result;
printf("Enter a number: ");
scanf("%d",&n);
result = checkStrange(n);
if(result==1)
{
printf("%d is a strange number.\n", n);
}
else
{
printf("%d is not a strange number.\n", n);
}
return 0;
}

17. #include
int strange(int digit);
main()
{
int digit;
printf("Given an input to check a strange number: ");
scanf("%d",&digit);
strange(digit);
}
int strange(int d)

{
int i,rem,flag=1;
while(d!=0)
{
rem=d%10;
d=d/10;
for(i=2;i<rem;i++)
{

if(rem%i==0)
{
flag=0;
break;
}
}
}
if(flag==1)
printf("\nGiven input is a strange number");
else
printf("\nGiven input is not a strange number");
}

18. Id-201210803

#include
using namespace std;

int strng(int d)
{
int i,j,t=1;
while(d!=0)
{
j=d%10;
d=d/10;
for(i=2;i>digit;
strng(digit);
}

19. #include
using namespace std;
int strang(int d);
main()
{
int digit;
cin>>digit;
strang(digit);
}
int strang(int d)
{
int i,j,t=1;
while(d!=0)
{
j=d%10;
d=d/10;
for(i=2;i<j;i++)
{
if(j%i==0)
{
t=0;
break;
}
}
}
if(t==1)
cout<<"this number is strange";
else
cout<<"this number is not strange";
}

20. #include
using namespace std;

class strange
{
public:
int num;
strange();
void show();
~strange();
};
strange::strange()
{
cout<<"Enter a number: ";
cin>>num;
}
void strange::show()
{
int i,rem=0,flag=0,flag1=0;
while(num!=0)
{
rem=num%10;
num=num/10;
for(i=2; i<=rem/2; i++)
{
if(rem%i==0)
{
flag=1;
break;
}
else
flag=0;
}

}
for(i=2; i<=num/2; i++)
{
if(num%i==0)
{
flag1=1;
break;
}
else
flag1=0;
}
if(flag==0&&flag1==0)
cout<<endl<<"This is a strange number."<<endl;
else
cout<<endl<<"This is not a strange number."<<endl;
}
strange::~strange()
{

}
main()
{
strange ob;
ob.show();
}

21. #include
using namespace std;
class strange
{
public:
int num;
strange();
void show();
~strange();
};
strange::strange()
{
cout<<"Enter a number: ";
cin>>num;
cout<<endl;
}
void strange::show()
{
int i, remain=0, flag1=0, flag2=0;
while(num!=0)
{
remain=num%10;
num=num/10;
for(i=2; i<=num; i++)
{
if(remain%i==0){
flag1=1;
break;
}
else
flag1=0;
}
}
for(i=2; i<=num/2; i++)
{
if(num%i==0){
flag2=1;
break;
}
else
flag2=0;
}
if(flag1==0 && flag2==0)
cout<<"Strange number..."<<endl;
else
cout<<"Not strange number..."<<endl;
}
strange::~strange()
{

}
int main()
{
strange obj;
obj.show();
return 0;
}

22. using C++

#include
using namespace std;

class cons
{
public:
int num;
cons(int i);
~cons();

void result();
};

cons::cons(int i)
{
num = i;
}

void cons::result()
{
int temp, check = 1;
while (num != 0){
temp = num % 10;
num /= 10;
for (int i = 2; i < temp; i++){
if (temp % i == 0)
check = 0;
break;
}
}

if (check == 1)
cout << "This number is a Strange number --\n";
else
cout << "This is not a Strange number --\n";
}

cons::~cons()
{
cout << "[+]MEMORY RELEASED[+]\n";
}

int main()
{
int i;
cout << "Enter that number you want to check --: ";
cin >> i;

cons obj(i);
obj.result();

return 0;
}

23. using constructor

#include
using namespace std;
class Strange
{
public:
int i,t,p,d;
Strange ();

~Strange ();
void result();
};
Strange ::Strange ()
{
cout<<"Enter a number :" ;
cin>>d;
}
Strange ::~Strange ()
{

}
void Strange ::result()
{
t=1;
while(d!=0)
{
p=d%10;
d=d/10;

for(i=2;i<p;i++)
{
if(p%i==0)
{
t=0;
break;
}
}

}
if(t==1)
cout<<"This is Strange number:";
else
cout<<"This is not Strange number :"<<"\n";
}
int main()
{
Strange sb;
sb.result();
}

24. #include
using namespace std;

class strange
{
public:
int num,i,temp=0;
strange();
~strange()
{
cout<<"Distructor active";
}
int func()
{
string check="ok";
while(num!=0)
{
temp=(num%10);
num=num/10;
for(i=2;i>num;
}

int main()
{
strange obj;
obj.func();
return 0;
}

id:201510660