CodeSolved

A comprehensive source of programming questions and exercises

Numbers filter in array

Practice Easy 1309/ Download 560 Views

Write a function to take an array containing numbers as input; Removes the pair numbers and the new array includes only individual numbers

19 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
def odd(lst):    
     odd_num_lst = []
     for item in lst:
        if (item % 2) != 0:
            odd_num_lst.append(item)
     return odd_num_lst
Behcoder Download Python
#include <iostream>
using namespace std;
int main(){
	int n;
	cout << "Enter how many number you wana enter: ";
	cin >> n;
	cout << "Enter numbers: ";
	int mary[n];
	for(int i=0; i<n; i++){
		cin >> mary[i];
	}
	for(int i=0; i<n; i++){
		cout << "a[" << i <<"] = " << mary[i] << endl;
	}
	int a = 0;
    for(int i=0; i<n; i++){
    	if(mary[i]%2!=0){
    	cout << "a fard [" << a <<"] = " << mary[i] << endl;
    	a++;
    }
    }
}
User 2720 Download C & C++
def filter_odd_numbers(arr):
    """
    این تابع یک آرایه شامل اعداد را به عنوان ورودی می‌گیرد
    و آرایه‌ای شامل فقط اعداد فرد را برمی‌گرداند.
    """
    # Use listing to filter individual numbers
    odd_numbers = [num for num in arr if num % 2 != 0]
    return odd_numbers

# Example of function use
input_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
result = filter_odd_numbers(input_array)
print("آرایه اعداد فرد:", result)
Mma123 Download Python
#include <iostream>
using namespace std;
void daryaft_add(int aaa[],int k){
	for(int i=0;i<k;i++){
		cout<<"add ha["<<i<<"]";
		cin>>aaa[i];
	}
}
void adad_fard(int fff[],int h){
	cout<<"namayesh arr fard[";
	for(int j=0;j<h;j++){
		if(fff[j]%2!=0){
		cout<< fff[j]<<",";
		}	
	}
	cout<<"]";	
	}
int main() {
	cout<<"x?";
	int x;
	cin>>x;
	int ARR[x];
	daryaft_add(ARR,x);
	adad_fard(ARR,x);
	return 0;
}
odd_numbers = []
n = int(input("How many numbers do you want to add: "))
for i in range(n):
    num = int(input("Enter num {}:".format(i+1)))
    if num%2!=0:
        odd_numbers.append(num)
    i+=1
print(odd_numbers)
Matin Download Python
def araye():
  l=[]
  while 1:
   print('for exit enter:0')
   i=int(input('int:'))
   if i==0:
    break
   elif i%2!=0:
    l.append(i)
  print(l)
araye()
Maryam.n Download Python
def odd(txt):
    odd_nums = ''
    for i in txt:
        if i.isdigit():
            if int(i) % 2 != 0:
                odd_nums += i
    return odd_nums

txt = input('text: ')
print(f'odd numbers in your text is: {odd(txt)}')
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

×
×
Close