Sie sind auf Seite 1von 5

Devolop a C program to insert an element into an array in any position .

#include<conio.h>
#include<stdio.h>
int main()
{
int i,k=0,a[100],n,loc,b,j;
printf("enter the array size: ");
scanf("%d",&n);
printf("enter the element: ");
for(i=0;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("enter the location ");
scanf("%d",&loc);
loc=loc-1;
printf("enter the element::");
scanf("%d",&b);
for(j=n;j>=loc;j--)
{
a[j+1]=a[j];
}
a[loc]=b;
n=n+1;
printf("after implementation :\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
getch();
}
Output:
enter the array size: 4
enter the element : 1
2
3
4
5
enter the location : 3
enter the element:: 45
after implementation :
1
2
45
4
5
Devolop a C program to delete an element into an array in any position .
#include <stdio.h>
#include <conio.h>
int main()
{
int a[50],i,pos,size;
printf("\nEnter size of the array: ");
scanf("%d",&size);
printf("\nEnter %d elements in to the array: ",size);
for(i=0;i<size;i++)

scanf("%d",&a[i]);
printf("\nEnter position where to delete: ");
scanf("%d",&pos);
i=0;
while(i!=pos-1)
i++;
while(i<10)
{
a[i]=a[i+1];
i++;
}
size--;
for(i=0;i<size;i++)
printf(" after implementation : %d",a[i]);
getch();
}
OUTPUT
Enter size of the array
Enter 5 elements in to
2
5
3
6
Enter position where to
after implementation :

:5
the array :4

delete :3
4 2 3 6

Devolop a C program to sorting the element of a list using INERTION SORT algorit
hm.
#include<conio.h>
#include<stdio.h>
int main()
{
int i, size, ptr, k, temp, p, ar [100];
printf("enter the array size :");
scanf("%d",&size);
ar[0]=-50000;
for(i=1;i<=size;i++)
{
printf("enter the element");
scanf("%d",&ar[i]);
}
for(k=2;k<=size;k++)
{
temp=ar[k];
ptr=k-1;
while(temp<ar[ptr])
{

ar[ptr+1]=ar[ptr];
ptr--;
}
ar[ptr+1]=temp;
}
printf("sorted array is\n");
for(i=1;i<=size;i++)
printf("%d\t",ar[i]);
getch();
}
OUTPUT
enter the
enter the
enter the
enter the
enter the
enter the

array size : 5
element :1
element :2
element :3
element :4
element :5

sorted array is
1
2
3

Devolop a C program to sorting the element of a list using SELECTION SORT algori
thm.
#include <stdio.h>
#include <conio.h>
int main()
{
int A[20], N, Temp, i, j;
printf("\n\n\t ENTER THE NUMBER OF TERMS...: ");
scanf("%d",&N);
printf("\n\t ENTER THE ELEMENTS OF THE ARRAY...:");
for(i=1; i<=N; i++)
{
scanf("\n\t\t%d", &A[i]);
}
for(i=1; i<=N-1; i++)
for(j=i+1; j<=N;j++)
if(A[i]>A[j])
{
Temp = A[i];
A[i] = A[j];
A[j] = Temp;
}
printf("\n\tTHE ASCENDING ORDER LIST IS...:\n");
for(i=1; i<=N; i++)
printf("\n\t\t\t%d",A[i]);
getch();
}
OUTPUT
ENTER THE NUMBER OF TERMS...:: 5
ENTER THE ELEMENTS OF THE ARRAY..1
3
4

7
2
THE ASCENDING ORDER LIST IS :
1
2
3
4
7

Devolop a C programe to creat a structure emp with the members : name ,age & add
ress .take 10 valus through keyboard and detailed information about employees in
tabular format . Also display the name of the employees whose age is more than
20.
#include<stdio.h>
#include<conio.h>
struct employee
{
char name[20],address[100];
int age;
};
int main()
{
struct employee emp[10];
int i;
for(i=0;i<10;i++)
{
printf("ENter the name of the employee: ");
fflush(stdin);
gets(emp[i].name);
printf("Enter the address: ");
fflush(stdin);
gets(emp[i].address);
printf("Age: ");
scanf("%d",&emp[i].age);
}
for(i=0;i<10;i++)
{
printf("\n%s\t%s\t%d\n",emp[i].name,emp[i].address,emp[i].
age);
}
for(i=0;i<10;i++)
{
if(emp[i].age>20)
printf(" \n\n\nname of the employees whose age is more than 20 are
: ");
printf("\n%s\t%s\t%d\n",emp[i].name,emp[i].address,emp[i].age);
}

getch();
}

OUTPUT
Enter the name of the employee: RAM
Enter the address: MUMBAI
Age: 18
Enter the name of the employeet: SHAM
Enter the address: DELHI
Age:
Enter the name of the employee: MADHU
Enter the address: KOLKATA
22
...................................................................
...................................................................
..................................................................
RAM
MUMBAI 18
SHAM
DELHI
21
MADHU KOLKATA
22
..................................................................
...................................................................
...................................................................
..................................................................
name of the employees whose age is more than 20 are :
SHAM
MADHU

DELHI
KOLKATA

21
22

Das könnte Ihnen auch gefallen