Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int add(int A[50], int n, int x)
- {
- int i ,j,index,arr1[50];
- if (n>50)
- return(-1);
- for(i=0;i<n;i++)
- {
- if(A[i]>x)
- {
- return(i);
- break;
- }
- }
- }
- int main()
- {
- int i,j,n,x,result,arr[50];
- printf("\nEnter how many element do you want : ");
- scanf("%d", &n);
- printf("\n\nEnter the elements of array : ");
- for(i = 0; i < n; i++)
- {
- scanf("%d", &arr[i]);
- }
- printf("\n\nEnter the element you insert in the array : ");
- scanf("%d", &x);
- result = add(arr,n,x);
- if(result==-1)
- {
- printf("\n%d can't be added successfully\n",x);
- }
- else
- {
- printf("\n%d is inserted at position: %d\n",x,result);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment