Code Box
----------------------------------------------
/*Program to find given numbers presence in another number in C
or
Program to find any number inside another number in C.
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num,num1,nf,rem,newnum,len,i,c;
clrscr();
len=0;
newnum=0;
c=0; //Counter Variable
printf("\n\tNumber Finder");
printf("\n-------------------------");
printf("\nEnter a number:");
scanf("%d",&num);
/*Single Digit number */
printf("\nEnter number to find:");
scanf("%d",&nf);
num1=num; //to save actual number
/*Number Reverse */
while(num1>=1)
{
rem=num1%10;
num1=num1/10;
newnum=newnum*10+rem;
len++;
}
for(i=1;i<=len;i++)
{
rem=newnum%10;
newnum=newnum/10;
if(rem==nf)
{
printf("\nNumber %d is present in %d at position %d.",nf,num,i);
}
else
{
c++; //Counter Variable
}
}
if(c==len) //Checking for absence
{
printf("\nNumber Not Found!!!");
}
getch();
}
No comments:
Post a Comment