Problem Statement
Write a C function checkdigit which takes as input an integer
x, and a number dig (an integer between 0 and 9), and checks
if the number x has dig as one of its digits. the function
returns 1 if the digit dig occurs in x, 0 otherwise.
#include<stdio.h>
int checkdig(int n,int search);
int main()
{
int n,search;
printf("enter the number ");
scanf("%d",&n);
printf("enter key to be searched ");
scanf("%d",&search);
if(checkdig(n,search)==1)
{
printf("%d occur in %d \n",search,n);
}
else
{
printf("%d does not occur in %d \n",search,n);
}
return 0;
}
int checkdig(int n,int search)
{
while(n>=1)
{
if(search==n%10)
{
return 1;
}
n=n/10;
}
return 0;
}
Write a C function checkdigit which takes as input an integer
x, and a number dig (an integer between 0 and 9), and checks
if the number x has dig as one of its digits. the function
returns 1 if the digit dig occurs in x, 0 otherwise.
#include<stdio.h>
int checkdig(int n,int search);
int main()
{
int n,search;
printf("enter the number ");
scanf("%d",&n);
printf("enter key to be searched ");
scanf("%d",&search);
if(checkdig(n,search)==1)
{
printf("%d occur in %d \n",search,n);
}
else
{
printf("%d does not occur in %d \n",search,n);
}
return 0;
}
int checkdig(int n,int search)
{
while(n>=1)
{
if(search==n%10)
{
return 1;
}
n=n/10;
}
return 0;
}
No comments:
Post a Comment