Numbers filter in array
Write a function to take an array containing numbers as input; Removes the pair numbers and the new array includes only individual numbers
Write a function to take an array containing numbers as input; Removes the pair numbers and the new array includes only individual numbers
let msg = 'error' alert(msg)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
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
def odd(lst): odd_num_lst = [] for item in lst: if (item % 2) != 0: odd_num_lst.append(item) return odd_num_lst
#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++; } } }
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)
#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)
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()
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)}')
Submitting answers is currently unavailable.
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.