Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****
- Question
- challenging program for student
- 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.
- *Test Case*
- Input
- 3 [5,4,6,7,9,8,1,17,14]
- Output
- 5
- Pair
- 4,1
- 7,4
- 9,6
- 8,5
- 17,14
- Input
- 2 [5,4,6,7,9,8,1,17,14]
- Output
- 4
- Pair
- 6,4
- 7,5
- 9,7
- 8,6
- ***/
- /**
- solution by Fahad
- **/
- #include<stdio.h>
- #include<conio.h>
- #include<math.h>
- int main()
- {
- int no,i,j,a,arr[20],temp,count=0;
- printf("\nEnter desire no=");
- scanf("%d",&no);
- printf("\nHow many numbers you want to insert");
- scanf("%d",&a);
- if(a>=20)
- {
- printf("Sorry upto 20 number is accepted");
- return 0;
- }
- for(i=0;i<a;i++)
- {
- printf("\nNo %d=",i+1);
- scanf("%d",&arr[i]);
- }
- printf("\nNumber You enter is :\n");
- for(i=0;i<a;i++)
- {
- printf("\n%d",arr[i]);
- }
- for(i=0;i<a;i++)
- {
- temp=arr[i];
- for(j=i+1;j<a;j++)
- {
- if(abs(temp-arr[j])==no)
- {
- count++;
- }
- }
- }
- printf("\nAfter subtraction of this number we found total %d pair",count);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment