Assignment number 3
Q1 program to delete the largest number from the array by passing it to function and function should not retun .
#include <stdio.h>
void taks(int arr[] ,int );
int main()
{int a;
printf("*****program to delete the largest number from the array*****\n\n");
printf("Enter the length of array : ");
scanf("%d",&a);
int arr[a];
for (int i=0;i<a;i++) {
printf("enter the element number %d : ",i+1);
scanf("%d",&arr[i]);
}
//calling the function
taks(arr,a);
}
void taks(int arr[],int n){
int value;
int arnew[n];
//save the array in new array for further use
for(int i=0;i<=n;i++){
arnew[i]=arr[i];
}
//finding the place where larger number is
for (int i = 0; i < n; ++i) {
if (arr[0] < arr[i]) {
arr[0] = arr[i];
value=i;
}
}
// deleting the larger number
for (int c = value ; c < n - 1 ; c++ )
arnew[c] = arnew[c+1];
printf("Resultant array is\n");
//printing the new array list
for( int c = 0 ; c < n - 1 ; c++ )
printf("%d\n", arnew[c]);
}
Comments
Post a Comment