zero_shubham1

solved_FEELS_GR8

Jul 4th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int opt=0,arr[50],i,n,s_id,temp,j,end_p;
  7.  
  8.     printf("Enter the number of numbers you want to enter: ");
  9.     scanf("%d",&n);
  10.  
  11.     end_p = n-1;
  12.  
  13.     printf("Enter the numbers: ");
  14.     for(i=0;i<n;i++)
  15.     {
  16.         scanf("%d",&arr[i]);
  17.  
  18.     }
  19.  
  20.     while(1)
  21.     {
  22.         printf("\nEnter 1 to print the list of numbers, 2 to delete the duplicates from the list or 3 to exit the program: ");
  23.         scanf("%d",&opt);
  24.  
  25.         switch(opt)
  26.         {
  27.         case 1:
  28.             for(i=0;i<=end_p;i++)
  29.                 printf("%d \t",arr[i]);
  30.             break;
  31.         case 2:
  32.             for(i=0;i<n-1;i++)
  33.             {
  34.                 s_id = i;
  35.                 for(j=i+1;j<n;j++)
  36.                 {
  37.                     if(arr[s_id]>arr[j])
  38.                         s_id = j;
  39.                 }
  40.                 temp = arr[i];
  41.                 arr[i] = arr[s_id];
  42.                 arr[s_id] = temp;
  43.  
  44.             }
  45.             printf("\nSorted.");
  46.  
  47.             for(i=0;i<=end_p;i++)
  48.             {
  49.                 while(arr[i]==arr[i+1])
  50.                 {
  51.                     for(j=i+1;j<=end_p;j++)
  52.                         arr[j] = arr[j+1];
  53.                     end_p--;
  54.                 }
  55.             }
  56.             printf("\nDeleted Duplicates.");
  57.             break;
  58.         case 3:
  59.             exit(0);
  60.  
  61.         default:
  62.             printf("Entered wrong option. Please try again!");
  63.         }
  64.  
  65.     }
  66.  
  67.  
  68.     return 0;
  69. }
Add Comment
Please, Sign In to add comment