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]); 

}

Result
*****program to delete the largest number from the array*****

Enter the length of array : 5
enter the element number 1 : 7
enter the element number 2 : 2
enter the element number 3 : 36
enter the element number 4 : 1
enter the element number 5 : 5
Resultant array is
7
2
1
5

Q2 Find the sum of all non prime number between the range of n and m along with n and m 

#include <stdio.h>

void taks(int ,int,int* );

int main()

{int a;

printf("Enter the n");

scanf("%d",&a);

int b;

printf("Enter the m");

scanf("%d",&b);

int *sum;

taks(a ,b ,sum );

printf("\nthe sum of the non prime number is : %d",*sum);

}



void taks(int low ,int high ,int *sum ){

    int check,i;

    int flag;

    int b=low;

 while (low <=high) {

      flag =0;

      if (low <= 1) {

         ++low;

         continue;

      }

      for (i = 2; i <= low / 2; ++i) {

         if (low % i == 0) {

            flag = 1;

            break;

         }

      }

      if (flag != 0){

      *sum=*sum+low;

      }

      ++low;

   }

   int con=b<=1;

   if(!con){

       *sum=*sum-1;

   }

   

'Result 
Enter the n10
Enter the m15

the sum of the non prime number is : 52

Comments