🚀 Code Challenge #115: Array Manipulation in C!
Hello Coders! 👩💻👨💻
Let's continue our coding journey with today's challenge – Manipulating Arrays! 🌐🔍
116: Remove Duplicates from Array
#include<stdio.h>
#include<conio.h>
void main()
{
int array[10];
int i, n, pos, element, found = 0;
clrscr();
printf("Enter total number of elements : ");
scanf("%d", &n);
printf("\nEnter the elements : \n");
for (i = 0; i < n; i++)
{
scanf("%d", &array[i]);
}
printf("Input array elements are\n");
for (i = 0; i < n; i++)
{
printf("\n%d", array[i]);
}
printf("\nEnter the element to be deleted : ");
scanf("%d", &element);
for (i = 0; i < n; i++)
{
if (array[i] == element)
{
found = 1;
pos = i;
break;
}
}
if (found == 1)
{
for (i = pos; i < n - 1; i++)
{
array[i] = array[i + 1];
}
printf("\nResultant array elements are : ");
for (i = 0; i < n - 1; i++)
{
printf("\n%d", array[i]);
}
}
else
{
printf("\nElement %d is not found in the array", element);
}
getch();
}
🤔 Challenge Task:
Modify the provided code to remove duplicates from the array and display the result.
Share with your friend
@programming_and_coding
Happy coding! 🚀💻 #CodeChallenge #CProgramming #ArrayManipulation
Hello Coders! 👩💻👨💻
Let's continue our coding journey with today's challenge – Manipulating Arrays! 🌐🔍
116: Remove Duplicates from Array
#include<stdio.h>
#include<conio.h>
void main()
{
int array[10];
int i, n, pos, element, found = 0;
clrscr();
printf("Enter total number of elements : ");
scanf("%d", &n);
printf("\nEnter the elements : \n");
for (i = 0; i < n; i++)
{
scanf("%d", &array[i]);
}
printf("Input array elements are\n");
for (i = 0; i < n; i++)
{
printf("\n%d", array[i]);
}
printf("\nEnter the element to be deleted : ");
scanf("%d", &element);
for (i = 0; i < n; i++)
{
if (array[i] == element)
{
found = 1;
pos = i;
break;
}
}
if (found == 1)
{
for (i = pos; i < n - 1; i++)
{
array[i] = array[i + 1];
}
printf("\nResultant array elements are : ");
for (i = 0; i < n - 1; i++)
{
printf("\n%d", array[i]);
}
}
else
{
printf("\nElement %d is not found in the array", element);
}
getch();
}
🤔 Challenge Task:
Modify the provided code to remove duplicates from the array and display the result.
Share with your friend
@programming_and_coding
Happy coding! 🚀💻 #CodeChallenge #CProgramming #ArrayManipulation