Skip to main content

Print the following series using for loop:- 1,8,27,64,125,216,......n JS

Copy to Clipboard console.log("Print the following series using for loop:- 1,8,27,64,125,216,......n"); let n ; function cubeseriesloop(n){ for(let i=0; i =0){ console.log(cubei); }else{ break; } } } console.log(cubeseriesloop(9));

Write a program to perform different operation on array (Insertion, Deletion, Search)

Program

 #include <stdio.h>

#include <stdlib.h>

void insert()

{

printf("Enter size of array : ");

int n;

scanf("%d", &n);

printf("Enter elements in array : ");

int a[n];

for (int i = 0; i < n; i++)

{

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

}

printf("Enter number to insert : ");

int num;

scanf("%d", &num);

printf("Enter position : ");

int pos;

scanf("%d", &pos);

int j = n;

printf("\nOriginal array : \n");

for (int i = 0; i < n; i++)

{

printf("%d = %d \n", i + 1, a[i]);

}

n = n + 1;

pos = pos - 1;

while (j >= pos)

{

a[j + 1] = a[j];

j = j - 1;

}

a[pos] = num;

printf("Array after insertion : \n");

for (int i = 0; i < n; i++)

{

printf("%d = %d \n", i + 1, a[i]);

}

}

void delete ()

{

printf("Enter size of array : ");


int n;

scanf("%d", &n);

printf("Enter elements in array : ");

int a[n];

for (int i = 0; i < n; i++)

{

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

}

printf("Enter position to delete : ");

int pos;

scanf("%d", &pos);

printf("Original array : \n");

for (int i = 0; i < n; i++)

{

printf("%d = %d \n", i + 1, a[i]);

}

int j = pos;

while (j < n)

{

a[j - 1] = a[j];

j = j + 1;

}

n = n - 1;

printf("Array after deletion : \n");

for (int i = 0; i < n; i++)

{

printf("%d = %d \n", i + 1, a[i]);

}

}

void search()

{

int a[5];

printf("Enter 5 elements : ");

for (int i = 0; i < 5; i++)

{

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

}

printf("Array Elements : \n");

for (int i = 0; i < 5; i++)

{

printf("%d\n", a[i]);

}

int element;

printf("Enter element to Search : ");

scanf("%d", &element);

for (int i = 0; i < 5; i++)

{

if (a[i] == element)


{

printf("Given element is successfully found ...\n");

exit(0);

}

}

printf("Given number not found...!\n");

}

void main()

{

while (1 < 2)

{

printf("Choose Operation : \n\t1. Insert\n\t2. Delete\n\t3. Search\n\t4. Exit\n");

int choice;

scanf("%d", &choice);

switch (choice)

{

case 1:

insert();

break;

case 2:

delete ();

break;

case 3:

search();

break;

case 4:

exit(0);

break;

default:

printf("Choose proper Option !");

break;

}

printf("\n\n");

}

}

Output
Choose Operation : 
1. Insert 
2. Delete 
3. Search 
4. Exit 1 Enter size of array : 5 
Enter elements in array : 2 4 6 8 9 
Enter number to insert : 1 
Enter position : 2 
Original array : 1 = 2 
 2 = 4 
 3 = 6 
 4 = 8 
 5 = 9 
 Array after insertion : 
 1 = 2 
 2 = 1 
 3 = 4 
 4 = 6 
 5 = 8 
 6 = 9 
 Choose Operation : 
 1. Insert 
2. Delete 
3. Search 
4. Exit

Comments

Popular posts from this blog

Screen Recorder Tool

Screen Recorder Tool Start Recording Stop Recording This the demo of the source code click above buttons to recording the screens, enjoy and download it   Creating a complete responsive screen recorder tool using the RecordRTC library involves multiple steps, including HTML, CSS, and JavaScript. Below is a simplified example to give you an idea of how you can implement this. Please note that this example might not cover all possible edge cases, and you might need to adapt and extend it for your specific needs.  First, make sure you include the RecordRTC library in your HTML. You can include it using a script tag in the <head> section of your HTML document: If you want the source code for it see the below video:

Write a program to sort given elements using bubble sort , insertion sort, and selection sort.

Program: #include <stdio.h> #include <stdlib.h> void bubble() { int n; printf("Enter Size of Array to Create : "); scanf("%d", &n); int a[n]; printf("Enter Elements of Array : "); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } printf("Unsorted Array : "); for (int i = 0; i < n; i++) { printf("%d ", a[i]); } for (int i = 0; i < n; i++) { for (int j = 0; j < n - i - 1; j++) { if (a[j] > a[j + 1]) { int tmp = a[j]; a[j] = a[j + 1]; a[j + 1] = tmp; } } } printf("\nSorted Array : "); for (int i = 0; i < n; i++) { printf("%d ", a[i]); } } void insertion() { int n; printf("Enter Size of Array to Create : "); scanf("%d", &n); int a[n]; printf("Enter Elements of Array : "); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } printf("Unsorted Array : "); for (int i = 0; i < n; i++) { printf("%d ", a[i]...