/* INPUT AN INTEGER N, FIND OUT THE POSITIONS OF OCCURRENCE OF
DIGITS 0,1,2,3,4,...9 IN THIS NUMBER. (CREATE A FUNCTION WHICH FINDS
THE POSITIONS OF OCCURRENCE OF A PARTICULAR DIGIT. THIS FUNCTION
CAN BE CALLED REPEATEDLY).
*/
#include<stdio.h>
#include<conio.h>
#define MAX 25
void main()
{
char arr[MAX],posof;
int i,present;
clrscr();
printf("Enter an integer");
scanf("%s",arr);
for(i=0;i<strlen(arr);i++)
{
if( !(arr[i]>='0' && arr[i]<='9') )
printf("The number is not an integer");
}
for(posof='0';posof<='9';posof++)
{
printf("The position of %c -->",posof);
for(i=0,present=0;i<strlen(arr);i++)
{
if(arr[i]==posof)
{
printf("%d ",i+1);
present++;
}
}
if(present==0)
printf("Not present");
printf("\n");
}
getch();
}
/*
=====OUT PUT=====
1.Enter an integer : 234876521
The position of 0 -->Not present
The position of 1 -->9
The position of 2 -->1 8
The position of 3 -->2
The position of 4 -->3
The position of 5 -->7
The position of 6 -->6
The position of 7 -->5
The position of 8 -->4
The position of 9 -->Not present
2.Enter an integer : xyz
The number is not an integer
The position of 0 -->Not present
The position of 1 -->Not present
The position of 2 -->Not present
The position of 3 -->Not present
The position of 4 -->Not present
The position of 5 -->Not present
The position of 6 -->Not present
The position of 7 -->Not present
The position of 8 -->Not present
The position of 9 -->Not present
*/
No comments:
Post a Comment