Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- /*
- 1. Accept ‘m’ integer number and store them in an array arr[m],
- 2. then divide it into two arrays odd and even.
- 3. Write a program in the programming language C and
- 4.(1) display the contents of odd array and even array
- 5.(2) display the maximum number of arr[m]
- 6.(3) display the maximum number of even array
- 7.(4) display the multiplication value of minimum and maximum numbers of odd array.
- */
- int main(){
- // # 1 task
- int array_size,odd_size=0,even_size=0,max_num_array = -1,max_num_even=-1,min_num_odd=10000,max_num_odd=-1;
- // array size taken
- printf("Enter arry size \n");
- scanf("%d",&array_size) ;
- //array creation
- int arr[array_size];
- printf("Enter arry elements \n");
- // array input taken
- int i;
- for(i=0;i<array_size;i++)
- {
- scanf("%d",&arr[i]);
- //odd-even check
- if(arr[i]%2==0)
- even_size++;
- else
- odd_size++;
- // maximum check
- if(arr[i]>max_num_array)
- max_num_array = arr[i];
- }
- // #2 task odd and even array can be of size different
- //even and odd array creation
- int even_array[even_size];
- int odd_array[odd_size];
- //value insertion
- int j,k;
- for(i=0,j=0,k=0;i<array_size;i++)
- {
- if(arr[i]%2==0)
- {
- even_array[k] = arr[i];
- // maximum check for even
- if(even_array[k]>max_num_even)
- max_num_even = even_array[k];
- k++;
- }
- else
- {
- odd_array[j] = arr[i];
- if(odd_array[j]>max_num_odd)
- max_num_odd = odd_array[j];
- if(odd_array[j]<min_num_odd)
- min_num_odd = odd_array[j];
- j++;
- }
- }
- // 10000+12222 = 5 sec 10 year smart human coder
- // 10-9 sec 1 sec computer fast
- printf(" *** main array *** \n");
- for(i=0;i<array_size;i++)
- {
- printf("%d ",arr[i]);
- }
- printf("\n *** odd array ***\n");
- for(i=0;i<odd_size;i++)
- {
- printf("%d ",odd_array[i]);
- }
- printf(" \n *** even array *** \n");
- for(i=0;i<even_size;i++)
- {
- printf("%d ",even_array[i]);
- }
- // maximuma array element print
- printf("\n maximum main array element is = %d ",max_num_array);
- printf("\n maximum even array element is = %d ",max_num_even);
- printf("\n the multiplication value of minimum and maximum numbers of odd array = %d",(max_num_odd*min_num_odd));
- }
- // index - 0 1 2 3 4 5
- // values - 50 30 55 56 79 80 - array use case - list list id = array index list value = array value
- // odd - 1,3 ,5,7,9 -9*1
- // even -
- /*
- #1 age theke jani- int arr[5] = {1,2,3,4,5};
- #2 user input dibe
- int array[5];
- array[0] = 10;
- array[1] = 10;
- array[2] = 10;
- array[3] = 10;
- array[4] = 10;
- i
- main = 1,3,5,8,7,9,4
- j
- odd = 1,3,5
- k
- even = 8
- // nested if else
- if
- if
- else
- else if
- if
- else if
- else
- else
- // max or min checking logic
- arr = 1,2,3,4,5,7,1
- max_num_array = 7
- arr[i] = 1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement