Computer Graphics Some Usefull Operations Check Now

Operations on one dimensional arrays:
♦️Insertion:
Steps for insertion operation👇👇
Step1: intialize k to n-1

Step2 :repeat following steps while k>=I
1. Shift a[k] to a[ k+1]
2.decrement k by 1

Stap3:copy new element at index i

Insert means to add a new element in to the array at specified position.considering c array having maximum size 10 having currently n=5 elements ,to insert an element at index 1, first all the elements from 1 to n-1 are shifted down by one position to make the space at index 1 and then new value is to be copied at index 1 as shown in.....

1. Program..
#include<studio.h>
#include<studio.h>
Void main()
{
   Int a[10];
   Int k,I,n,Val,post;

Printf("enter size of array:");
Scanf("%d",&n);
Printef("add array element");
For(I=0;I<n;I++)
Scanf("%d",&a[ I]);

Printf("enter pos to insert:");
Scanf("%d",&pos);

Printf("enter value:");
Scanf("%d",&Val);

For(k=n-1;k>=pos;k--)
A[k+1]= a[k];
A[pos]= val;
N=n+1

Printf("array after insertion");
For(I=0;I<n;I++)
Printf("%d",a[i]);
Printf("\n");
}
Output:
Enter size of the array: 5
Enter array elements : 10 20 40 50
Enter value : 30
Array after insertion : 10 20 30 40 50

♦️DELETION :
Steps  for deletion operation👇👇
Step 1: if I= n-1,return with n-1.

Step 2:repeat following steps for k=I+1 to n-1
1. Shift a[k] to a[k-1]
2. Increment k by 1



Delete operation removed an element from the specified index. This requires all the elements from next position to last position to be shifted up.
2.Program..

#include<studio.h>
#include<studio.h>
Void main()
{
   Int a[10];
   Int k,I,n,Val,post;

Printf("enter size of array:");
Scanf("%d",&n);
Printef("add array element");
For(I=0;I<n;I++)
Scanf("%d",&a[ I]);

Printf("enter pos to insert:");
Scanf("%d",&pos);

For(k=pos+1; k<=n-1;k++)
    A[k-1]=a[k];
n=n-1

Printf("array after deletion");
For(I=0;I<n;I++)
Printf("%d",a[i]);
Printf("\n");
}

Output:
Enter size of the array : 5
Enter array elements : 10 20 30 40 50
Enter pos to delete : 2
Array after deletion : 10 20 40 50

♦️SEARCHING :
The searching operation is used to find whether the desert data is present in a set of data or not . If it is present,the search operation provides its position.


3.Program :

#include<studio.h>
#include<conio.h>

Void main()
{
   Int a[50];
   Int I,n ,Val,flag=0;
Printf("enter size of the array:");
Scanf("%d",&a[I]);

Printf(" enter value");
Scanf("%d",& Val);

For(I=0; I< n;I++){
    If( Val== a[I]){
Printf("data found at position :%n",I+1);
      Flag=1;
   }
 }
If(!flag)
    Printf ("data is not found\n");
}

Output
Enter size of the array : 5
Enter array elements : 12 34 5 78 56
Enter value : 78
Data found at position : 4




Post a Comment

2 Comments