Wednesday, 3 September 2014

Advancement of topic "Test Class"

//This code will work properly with the duplicacy of elements in the array
#include<stdio.h>
#include"conio.h"
float main()
{
int list[100],n,i,x,t,p[100],j; //Declaration of variable;
printf("Enter the size of list: ");
scanf("%d",&n); //Entering the size of array 'list'
printf("Enter the elements: ");
for(i=0;i<n;i++)
{
scanf("%d",&list[i]); //Insertion of elements in array 'list'
}
printf("Enter the element to be here: ");
scanf("%d",&x); //Entering the element whose index has to be find
p[0]=-1;
j=0;
for(i=0;i<n;i++)
{
if(list[i]==x) //Matching each element of array 'list' with the entered element
{
p[j]=i; //Assinging the index value to variable p if the match success
j++;
}
}
i=0;
do
{
if(p[i]>=0)
{
printf("\nIndex of element %d is %d",x,p[i]); //Position of element i.e. index value in array 'list'
                        printf("\tPosition of element %d is %d",x,p[i]+1); //Position of element i.e. normal position in array 'list'
}
else if(p[i]<=0)
{
printf("Try again");
}
i++;
}while(i<j);
        getch();                                                    //getch() function is not required in DEV C++ compiler
return 0;
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.