Problem statement
Write a c program to check weather number1 exist in number2 or not,number1 need not to be single digit number. Without using array.
#include<stdio.h>
int check(int n,int sea);
int ten_pow_n(int y);
int main()
{
int sea,n,y;
printf("enter the integer ");
scanf("%d",&n);
printf("enter the number to be search ");
scanf("%d",&sea);
y=check(n,sea);
if(y==1)
{
printf("%d exist in %d \n",sea,n);
}
else
{
printf("%d does not exist in %d \n",sea,n);
}
return 0;
}
int check(int n,int sea)
{
int y,div;
y=no_of_dig(sea);
div=ten_pow_n(y);
while(n>=sea)
{
if(sea==n%div)
{
return 1;
}
n=n/10;
}
return 0;
}
int no_of_dig(int sea)
{
int count=0;
while(sea>=1)
{
sea=sea/10;
count++;
}
return count;
}
int ten_pow_n(int y)
{
int mul=1,i;
for(i=0;i<y;i++)
{
mul=mul*10;
}
return mul;
}
Write a c program to check weather number1 exist in number2 or not,number1 need not to be single digit number. Without using array.
#include<stdio.h>
int check(int n,int sea);
int ten_pow_n(int y);
int main()
{
int sea,n,y;
printf("enter the integer ");
scanf("%d",&n);
printf("enter the number to be search ");
scanf("%d",&sea);
y=check(n,sea);
if(y==1)
{
printf("%d exist in %d \n",sea,n);
}
else
{
printf("%d does not exist in %d \n",sea,n);
}
return 0;
}
int check(int n,int sea)
{
int y,div;
y=no_of_dig(sea);
div=ten_pow_n(y);
while(n>=sea)
{
if(sea==n%div)
{
return 1;
}
n=n/10;
}
return 0;
}
int no_of_dig(int sea)
{
int count=0;
while(sea>=1)
{
sea=sea/10;
count++;
}
return count;
}
int ten_pow_n(int y)
{
int mul=1,i;
for(i=0;i<y;i++)
{
mul=mul*10;
}
return mul;
}
No comments:
Post a Comment