Computer Science, asked by aditya8996, 9 months ago

Write a program that inputs maximum 10 numbers but stops as soon as 4 even numbers are entered.​

Answers

Answered by sswaraj04
6

Answer:

Explanation:

int arr[10],count=0;

for(int i=0;i<10;i++)

{

int num;

cout<<"enter a number";

cin>>num;

if(num%2==0)

count++;

if(count<4)

arr[i]=num;

else

break;

}


sswaraj04: it's a general answer
sswaraj04: use this logic for any language and complete according to it
rakeshchennupati143: you wrote the program in c++ dude we can say it by seeing your out and in statements
sswaraj04: and already he liked the answer if you know better you are free to answer
rakeshchennupati143: if i can write the program in python it will be completed in 3 lines
sswaraj04: sure, instead of reporting my answer if you have written your answer it wd be more helpful
rakeshchennupati143: but dev approved your program so cool..! did you see my report is deleted
sswaraj04: yup bad luck dude!!
sswaraj04: and he is not dev simply moderator
rakeshchennupati143: i don't want your answer to get deleted, i reported in mistakes in the answer and told there was no header that's it, i dont know it will be deleted even in mistakes in the answer option is given
Answered by rakeshchennupati143
3

program in python:

for i in range ( 10 ):

     num = int ( input ( "Enter a number : " ) )

     if num == 4 : break

Explanation:

  • first line of code says loop until the i value is less than 10
  • default i value will be taken as 0 so the loop will iterate 10 times
  • 2nd line input takes input from the user the int() method takes only the integer value, when you input a character or string it will show error
  • 3rd line checks if the input num is equal to 4 or not, if true it breaks from the loop
  • false the loop will again iterate by checking condition.

---Hope you understood my program.  :)

Similar questions