Advertisement
Guest User

code

a guest
Dec 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include<stdio.h>
  2. int add(int A[50], int n, int x)
  3. {
  4. int i ,j,index,arr1[50];
  5. if (n>50)
  6. return(-1);
  7. for(i=0;i<n;i++)
  8. {
  9. if(A[i]>x)
  10. {
  11. return(i);
  12. break;
  13. }
  14. }
  15. }
  16. int main()
  17. {
  18. int i,j,n,x,result,arr[50];
  19. printf("\nEnter how many element do you want : ");
  20. scanf("%d", &n);
  21. printf("\n\nEnter the elements of array : ");
  22. for(i = 0; i < n; i++)
  23. {
  24. scanf("%d", &arr[i]);
  25. }
  26. printf("\n\nEnter the element you insert in the array : ");
  27. scanf("%d", &x);
  28.  
  29. result = add(arr,n,x);
  30.  
  31. if(result==-1)
  32. {
  33. printf("\n%d can't be added successfully\n",x);
  34. }
  35. else
  36. {
  37. printf("\n%d is inserted at position: %d\n",x,result);
  38. }
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement