0% found this document useful (0 votes)
4 views3 pages

11

The document contains code examples in Python and C for finding the largest number in an array and removing duplicate elements from an array. It demonstrates the use of loops and conditionals in both languages to achieve these tasks. Additionally, it provides multiple methods for removing duplicates in Python and C.

Uploaded by

csed2k27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

11

The document contains code examples in Python and C for finding the largest number in an array and removing duplicate elements from an array. It demonstrates the use of loops and conditionals in both languages to achieve these tasks. Additionally, it provides multiple methods for removing duplicates in Python and C.

Uploaded by

csed2k27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

-->1.

using for loop print the largest number


arr = [25, 11, 7, 75, 56];
max = arr[0];
for i in range(0, len(arr)):
if(arr[i] > max):
max = arr[i];
print(str(max));
-->1.in c language
#include <stdio.h>

int main()
{

int size, i, largest;

printf("\n Enter the size of the array: ");


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

printf("\n Enter %d elements of the array: \n", size);

for (i = 0; i < size; i++)


{
scanf("%d", &array[i]);
}

largest = array[0];

for (i = 1; i < size; i++)


{
if (largest < array[i])
largest = array[i];
}

printf("\n largest element present in the given array is : %d", largest);

return 0;

-->2.remove duplicate elements in the array


def Remove(duplicate):
final_list = []
for num in duplicate:
if num not in final_list:
final_list.append(num)
return final_list

# Driver Code
duplicate = [10,20,30,30,50,10,10,40,60,10]
print(Remove(duplicate))

-->2.another way
# HOW TO REMOVE DUPLICATES FROM A LIST:
# 1) CREATE A LIST
my_list = [1, 2, 3, 4, 5, 5, 5, 1]
# 2) CONVERT IT TO A SET AND THEN BACK INTO A LIST
my_list = list(set(my_list))
# 3) DONE!
print(my_list)

-->2. in c language
#include<stdio.h>
#include<stdlib.h>
int main(){
int a[50],i,j,k, count = 0, dup[50], number;
printf("Enter size of the array\n");
scanf("%d",&number);
printf("Enter Elements of the array:\n");
for(i=0;i<number;i++){
scanf("%d",&a[i]);
dup[i] = -1;
}
printf("Entered element are: \n");
for(i=0;i<number;i++){
printf("%d ",a[i]);
}
for(i=0;i<number;i++){
for(j = i+1; j < number; j++){
if(a[i] == a[j]){
for(k = j; k <number; k++){
a[k] = a[k+1];
}
j--;
number--;
}
}
}
printf("\nAfter deleting the duplicate element the Array is:\n");
for(i=0;i<number;i++){
printf("%d ",a[i]);
}
}

-->2.another way in c language


/* C program to remove duplicate elements in an array */
#include<stdio.h>
// Code without the usage of pointers
int remove_duplicate_elements(int arr[], int n)
{

if (n==0 || n==1)
return n;

int temp[n];

int j = 0;
int i;
for (i=0; i<n-1; i++)
if (arr[i] != arr[i+1])
temp[j++] = arr[i];
temp[j++] = arr[n-1];

for (i=0; i<j; i++)


arr[i] = temp[i];

return j;
}
int main()
{
int n;
scanf(“%d”,&n);
int arr[n];
int i;
for(i = 0; i < n; i++)
{
scanf(“%d”,&arr[i]);
}

n = remove_duplicate_elements(arr, n);

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


printf(“%d “,arr[i]);

return 0;
}

You might also like