Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int opt=0,arr[50],i,n,s_id,temp,j,end_p;
- printf("Enter the number of numbers you want to enter: ");
- scanf("%d",&n);
- end_p = n-1;
- printf("Enter the numbers: ");
- for(i=0;i<n;i++)
- {
- scanf("%d",&arr[i]);
- }
- while(1)
- {
- printf("\nEnter 1 to print the list of numbers, 2 to delete the duplicates from the list or 3 to exit the program: ");
- scanf("%d",&opt);
- switch(opt)
- {
- case 1:
- for(i=0;i<=end_p;i++)
- printf("%d \t",arr[i]);
- break;
- case 2:
- for(i=0;i<n-1;i++)
- {
- s_id = i;
- for(j=i+1;j<n;j++)
- {
- if(arr[s_id]>arr[j])
- s_id = j;
- }
- temp = arr[i];
- arr[i] = arr[s_id];
- arr[s_id] = temp;
- }
- printf("\nSorted.");
- for(i=0;i<=end_p;i++)
- {
- while(arr[i]==arr[i+1])
- {
- for(j=i+1;j<=end_p;j++)
- arr[j] = arr[j+1];
- end_p--;
- }
- }
- printf("\nDeleted Duplicates.");
- break;
- case 3:
- exit(0);
- default:
- printf("Entered wrong option. Please try again!");
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment