Simple program of c language related to array

1-Write a simple program to reverse an array. 
Programming 5 axis cnc, java web services rest, java spring tutorial, java rest api,java point, java virtual machine, java executor framework, java for windows 7, restful  web services java, java web services soap, java 8 download, programming game ai by example, programming questions in java, programming quotes, programming for problem solving, programming with mosh, programming near me, programming in visual basic, programming python pdf, programming r, programming aptitude test, c program to find sum of n numbers using for loop, c program to find sum of n numbers using function, sum of numbers from 1 to 100 in c, c program for sum of two numbers, c program to find multiples of a number, c program to find sum of n numbers using array, c program to find sum of 10 numbers using function, how to find multiples of a number in c++,
Array program

#include<stdio.h>

#include<conio.h>

int main()

{

int c, d, n, a[100], b[100];

printf ("\n\nEnter number of elements in array :");

scanf ("%d", &n);

printf ("\n\nEnter %d elements\n", n);

for(c = 0; c < n; c++)

scanf ("%d", &a[c]);

for(c = n-1, d = 0; c >= 0; c--, d++)

b[d] = a[c];

for(c = 0; c < n; c++)

a[c] = b[c];

printf("\n\n Resultant array is: ");

for(c = 0; c < n; c++)

printf("%d", a[c]);

return 0;

}

Output:-

Enter number of elements in array :- 5

Enter 5 elements

2

3

4

5

6

Resultant array is: 6 5 4 3 2

Some basic programs of Operators in c language

2- a simple program to insert an element in an array.


#include<stdio.h>

#include<conio.h>

int main()

{

int array[100], position, c, n, value;

printf("\n\nEnter number of elements in array:");

scanf("%d", &n);

printf("\n\nEnter %d elements\n", n);

for(c = 0; c < n; c++)

scanf("%d", &array[c]);

printf("\n\nEnter the location where you want to insert new element: ");

scanf("%d", &position);

printf("\n\nEnter the value to insert: ");

scanf("%d", &value);

for(c = n-1; c >= position-1; c--)

array[c+1] = array[c];

array[position - 1] = value; // insertin given value

printf("\n\nResultant array is: ");

for(c = 0; c <= n; c++)

printf("%d ", array[c]);

return 0;

}

Output:-

Enter number of elements in array:- 4

Enter 4 elements

3

4

5

6

Enter the location where you want to insert new element :- 3

Enter the value to insert: 55

Resultant array is: 3 4 55 5 6

3- Write a simple program to delete an element from array, where the position of element to be deleted is given by user.


#include<stdio.h>

int main ()

{

int array [100], position, c, n;

printf ("\n\nEnter number of elements in array:");

scanf ("%d", &n);

printf ("\n\nEnter %d elements\n", n);

for (c = 0; c < n; c++)

scanf("%d", &array[c]);

printf ("\n\nEnter the location where you want to delete element from: ");

scanf ("%d", &position);

if (position >= n+1)

printf ("\n\nDeletion not possible\n\n");

else

for (c = position-1; c < n-1; c++)

array[c] = array[c+1];

printf("\n\nResultant array is: ");

for (c = 0; c < n-1; c++)

printf("%d ", array[c]);

return 0;

}

Output :-

Enter number of elements in array :-6

Enter 6 elements

2

3

4

5

6

7

Deletion not possible :- 3

Resultant array is: 2 3 5 6 7

4- a simple program to delete an element from array, where the element to be deleted is given by user.


#include<stdio.h>

int main()

{

int array[10], element, c, n, pos;

int found = 0;

printf("\n\nEnter number of elements in array:");

scanf("%d", &n);

printf("\n\nEnter %d elements\n", n);

for(c = 0; c < n; c++)

scanf("%d", &array[c]);

printf("\n\nThe input array is: ");

for(c = 0; c < n; c++)

printf("%d", array[c]);

printf("\n\nEnter the element to be deleted: ");

scanf("%d", &element);

for(c = 0; c < n; c++)

{

if(array[c] == element)

{

found = 1;

pos = c;

break; // terminate the loop

}

}

if(found == 1) // the element to be deleted exists in the array

{

for(c = pos; c < n-1; c++)

array[c] = array[c+1];

}

else

printf("\n\nElement %d is not found in the array\n\n", element);

printf("\n\nResultant array is: ");

for(c = 0; c < n-1; c++)

printf("%d ",array[c]);

return 0;

}

Output:- Enter number of elements in array:5

Enter 5 elements

4

5

6

7

8

The input array is: 4 5 6 7 8

Enter the element to be deleted: 6

Resultant array is: 4 5 7 8


Some special and important program of c language and c++

Post a Comment

0 Comments