Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Using Repetition:

Write a program that will prompt the user to enter a number. The program will then repeat a number of times using the number the user has entered in the first step. The program should then check each number in the loop to decide whether it is an even number or an odd number. When the program has finished it should display a summary of the even and odd numbers.

Example output if a user inputs the number 3: 1 is odd
2 is even
3 is odd
Summary: 1 even, 2 odd
Posted
Comments
Kornfeld Eliyahu Peter 11-May-14 7:00am    
How much you willing to pay for that?
Richard MacCutchan 11-May-14 7:13am    
You already have the pseudo code in your question.
[no name] 11-May-14 8:38am    
You need a pseudo coder.
BillWoodruff 11-May-14 12:11pm    
homework.

PROGRAM PrintOddEven:
    Read number;
    Set x = 1;
    Set odd = 0;
    Set even = 0;
    WHILE (x <= number)
            IF (x/2 gives a remainder)
                THEN Print x + " is odd";
                     odd = odd + 1;
                ELSE Print x + " is even";
                     even = even + 1;
           END IF;
           x= x + 1;
   END WHILE;
   Print even + " even " + odd + " odd ";
END
 
Share this answer
 
v2
C#
int k = 10; //User input
var sb = new StringBuilder();
Enumerable.Range(1, k).ToList().ForEach(p => sb.AppendLine(p + " is " + (p % 2 == 0 ? "even" : "odd")));
string result = sb.ToString();
 
Share this answer
 
v2
Comments
Kornfeld Eliyahu Peter 11-May-14 7:15am    
Pseudo code?
Emre Ataseven 11-May-14 7:21am    
Tag is C#, so it can be alternative for someone
Try something like
int array a;  //Input
for(int i; i<=a.Count; i++)
{
   if ((a mod 2) == 1)
   {
      Print ('odd number');
   }
   else
   {
      Print ('even number');
   }
}
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 11-May-14 7:16am    
Pseudo code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900