netx_iit

Challenging program

Jul 18th, 2020 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. /****
  2. Question
  3. challenging program for student
  4. Write a program which takes a number(x) and a list of number(numList) as a input and print number of pairs made from numList that are equal to x.After subtraction.
  5.  
  6. *Test Case*
  7. Input
  8. 3 [5,4,6,7,9,8,1,17,14]
  9.  
  10. Output
  11. 5
  12.  
  13. Pair
  14. 4,1
  15. 7,4
  16. 9,6
  17. 8,5
  18. 17,14
  19.  
  20. Input
  21. 2 [5,4,6,7,9,8,1,17,14]
  22.  
  23. Output
  24. 4
  25.  
  26. Pair
  27. 6,4
  28. 7,5
  29. 9,7
  30. 8,6
  31.  
  32. ***/
  33.  
  34. /**
  35. solution by Fahad
  36. **/
  37.  
  38. #include<stdio.h>
  39. #include<conio.h>
  40. #include<math.h>
  41. int main()
  42. {
  43.     int no,i,j,a,arr[20],temp,count=0;
  44.     printf("\nEnter desire no=");
  45.     scanf("%d",&no);
  46.     printf("\nHow many numbers you want to insert");
  47.     scanf("%d",&a);
  48.     if(a>=20)
  49.     {
  50.         printf("Sorry upto 20 number is accepted");
  51.         return 0;
  52.     }
  53.     for(i=0;i<a;i++)
  54.     {
  55.         printf("\nNo %d=",i+1);
  56.         scanf("%d",&arr[i]);
  57.     }
  58.     printf("\nNumber You enter is :\n");
  59.     for(i=0;i<a;i++)
  60.     {
  61.         printf("\n%d",arr[i]);
  62.     }
  63.     for(i=0;i<a;i++)
  64.     {
  65.         temp=arr[i];
  66.         for(j=i+1;j<a;j++)
  67.         {
  68.             if(abs(temp-arr[j])==no)
  69.             {
  70.                 count++;
  71.             }
  72.         }
  73.     }
  74.     printf("\nAfter subtraction of this number we found total %d pair",count);
  75.     return 0;  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment