Printing just even numbers from user input values.

This is a discussion on Printing just even numbers from user input values. within the C Programming forums, part of the General Programming Boards category; I have one last problem, the catch here is to not use arrays: Here's the problem: [spoiler] Write a C ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    11

    Printing just even numbers from user input values.

    I have one last problem, the catch here is to not use arrays:

    Here's the problem:

    [spoiler]
    Write a C program to prompt the user to enter five random integers from the keyboard and print only the even numbers. Also print the sum of the even numbers. The integers may be positive or negative.
    [/spoiler]

    My attempt:
    Code:
    #include<stdio.h>
    #include<conio.h>
    int main();
    {
    int a,b,c,d,e;
    
    
    scanf("%d%d%d%d%d",a,b,c,d,e);
    
    
    if (a%2==0)
    p
    .....
    I'm lost from this point and just need some hints/help on what to do to store values that are even and display them in a loop, then add them.
    Last edited by tadm123; 10-03-2012 at 05:22 PM.

  2. #2
    Registered User
    Join Date
    Oct 2012
    Posts
    10
    Well, you can use the command "for" to test the five numbers. but if you want to go one by one, you just need to write a printf("%d", a);, and then u check next number, and if he is even, you printf him too, and about the sum, you can use some variable to be incremented whenever the number is even. (just remember to initialize it)


    EDIT: ...
    Last edited by frank1; 10-03-2012 at 05:33 PM. Reason: grammar

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,309
    It sure doesn't look like you're lost. I mean, you have the odd/even test figured out, and I'm guessing, based on your other threads, that you know how to print strings and numbers, and how to do basic math. The values are stored in the variables you read into with scanf.

    Given that your other thread from today was for an exam, I'm hesitant to give too much help, since this might also be an exam question. Perhaps you could give it a little more effort on your own, and post your best attempt, and tell us more specifically what parts of odd/even testing, summation or printing you are having trouble with.

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    11
    Sure sounds good.

  5. #5
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,304
    I'd be thinking to use 'for' and then 'continue' for odd numbers
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing out previously entered user input!
    By SimarGill in forum C Programming
    Replies: 9
    Last Post: 12-04-2011, 09:19 PM
  2. Structure, user input and printing out results
    By alvarito in forum C Programming
    Replies: 3
    Last Post: 10-04-2011, 11:04 AM
  3. Printing a Solid Square based on user input
    By ThatBoy1124 in forum C Programming
    Replies: 3
    Last Post: 03-01-2011, 09:07 PM
  4. Printing asterisks using user input
    By celticpride in forum C Programming
    Replies: 4
    Last Post: 02-10-2011, 08:43 PM
  5. How to let the user input values for an array...
    By TerranAce007 in forum C++ Programming
    Replies: 2
    Last Post: 08-24-2002, 03:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21