how to print the sum of odd and even numbers taking upper and lower limit from user

how to print the sum of odd and even numbers taking upper and lower limit from user..program in c++ language

Edited 4 Years Ago by tamana: n/a

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a cheater. 
    If you use that code [i]you[/i] are a cheater.
[*]Do [b]not[/b] bore us with how new you are. We can tell by your code.
- Do not apologize. We were all new, and unless you are completely 
  brain dead you will get better.
- Do not ask us to "take it easy on you."
- Do not say "I don't know what's going on." That's obvious since
  you posted for help. Use that time wisely by [b]explaining[/b] as best 
  you can so we can help.
[*]Do not apologize for posting 'late'. We don't have any expectations on when you should be posting - 10 minutes or 10 days. We aren't timing your responses.
[*][b]Do not post your requirements and nothing else. [/b]We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we [i]will[/i] be hard on you.
[*]Do not attach files except when absolutely necessary. Most of us are not going to download files.  Add the information to your post.
[*][b]Do not tell us how urgent it is.[/b] Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
[*]Create a [b][i]good[/i][/b] title for your post. The title [b]C++[/b] in the C++ forum is bloody redundant and worthless!  [b]What's wrong?[/b] equally so. Specifically what are you having trouble with? [i]There[/i] is your title. [i](note: [b]my program[/b] is not the answer.)[/i]
[/list]
Think more about your next post so we don't have to play 20 questions to get the info we need to help you.

[/boilerplate_help_info]

int odd = 0;
int even = 0;
// now prompt for some values not shown here
// I'll leave that up for you to figure out.

// print the values
printf("odd = %d, even = %d\n", odd,even);

Edited 4 Years Ago by Ancient Dragon: n/a

hi
i made the last program and now i have a program i have to find the three greatest numbers in an array i have given the size of array and the condition but still its not giving me the right answer

Heres a Basic Formula, on how to get totals of odd + evens.
should help you along, some explantions below, but fairly straightforward.

#include <iostream>
using namespace std;
int main(){
  int initialnum = 0;
  int odd = 0;
  int even = 0;
  cout << "Enter Number Of Numbers" << endl;
  cin >> initialnum;
  if(initialnum %2 == 0){ //if %2 not equal 1 their is a remainder of 1.
   odd = initialnum /2;
   even = initialnum /2;
  }else{
   odd = (initialnum / 2) + 1; // if remainder of 1 means you got odd numbers.
   even = initialnum / 2;
  }
  cout << "How Many odd Numbers " << odd << endl;
  cout << "How Many Even Numbers" << even << endl;
  /* Taking Sums And Adding Up Now */
  int oddpt[odd];
  int evenpt[even];
  int oddtotal =0;
  int eventotal=0;
  int oddcounter = odd;
  int evencounter = even;
 /* Multiply By Itself sub 1 to Get Odd Number; */
  for(int i = 0; i < oddcounter; i++){
    oddpt[i]= (odd *2) - 1;
    odd--;
    oddtotal += oddpt[i];
  }
  /* Total For Even Numbers */
  for(int i = 0; i < evencounter; i ++){
    evenpt[i] = (even *2);
    even--;
    eventotal += evenpt[i];
  }
  cout << oddtotal << endl;
  cout << eventotal << endl;
}

Version 1:
set variable to hold largest value to be value of first element in the array.
Check each element in the array from index 1 to less than total number of elements in the array. If current element is the larger than currently recorded largest value, assign current value to the variable holding the largest value.

Version 2:
sort the array. Use either the first or last element of array depending what order the array is sorted.

This article has been dead for over six months. Start a new discussion instead.