| |

VerySource

 Forgot password?
 Register
Search
View: 1674|Reply: 10

How to edit this in C ++? ? ?

[Copy link]

3

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-6 15:20:01
| Show all posts |Read mode
Write the function int OddSum (int m, int n) to find the odd sum of m to n (including m, n). (0 <m <n <1000, m and n are integers), and call OddSum (80, 200) to find the odd sum between 80 and 200


Result: Sum of odd numbers from 80 to 200: 8400

Don't understand? ? ? ?

Please help

Thank you
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Korea, Republic of

Post time: 2020-1-6 15:48:01
| Show all posts
Homework
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-6 16:18:02
| Show all posts
Isn't it the same as C?
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-22 15:18:02
| Show all posts
#include <iostream.h>
int OddSum (int m, int n)
{int i, sum = 0;
 i = m;
 while (i <= n)
 {if (i% 2 == 1)

 {sum = sum + i;
 i = i + 2;}
 else i ++;
 }
 return sum;
}
void main ()
{
int m, n;
cout << "Please enter m, n (0 ~ 1000):";
cin >> m >> n;
int s = OddSum (m, n);
cout << "s =" << s << endl;
}
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-13 23:45:02
| Show all posts
Support upstairs
Reply

Use magic Report

0

Threads

1

Posts

342.00

Credits

Full Member

Rank: 3Rank: 3

Credits
342.00

 China

Post time: 2020-3-15 15:21:08
| Show all posts
Upstairs upstairs
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-31 16:15:02
| Show all posts
#include <iostream>
using namespace std;

int OddSum (int m, int n)
{
int Sum = 0;
for (int i = m; i <= n; i ++)
{
if (i% 2 == 0)
continue;
else
Sum + = i;
}
return Sum;
}

int main () {
int Num1, Num2;

cout << "Please enter the first number: (0 ~ 1000)";
cin >> Num1;
cout << "Please enter the second number: (0 ~ 1000)";
cin >> Num2;

The odd sum between cout << "\n" << Num1 << "and" << Num2 << "is:" << OddSum (Num1, Num2) << endl;


return 0;
}
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-4-17 09:30:02
| Show all posts
int OddSum (int m, int n);

int _tmain (int argc, _TCHAR * argv [])
{
cout << OddSum (80, 200);
  return 0;
}

int OddSum (int m, int n)
{
int sum = 0;
int i = m; // if m is an odd
if (! (m% 2)) // is m an even
i ++;
while (i <= n)
{
sum + = i;
i + = 2; // search for next number
}
return sum;
}
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-9 23:15:01
| Show all posts
Do not use for, while loop, use formula directly, efficiency is not higher!
Reply

Use magic Report

0

Threads

1

Posts

0.00

Credits

Newbie

Rank: 1

Credits
0.00

 China

Post time: 2020-5-17 13:00:57
| Show all posts
<? xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns: android = "http://schemas.android.com/apk/res/android"
    package = "person.wangchen11.sweep"
    android: versionCode = "1"
    android: versionName = "1.0">

    <uses-sdk
        android: minSdkVersion = "9"
        android: targetSdkVersion = "9" />
    <uses-permission android: name = "android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android: name = "android.permission.INTERNET" />
    <uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android: allowBackup = "true"
        android: icon = "@ drawable / ic_launcher"
        android: label = "Minesweeper">
        <activity
            android: name = "person.wangchen11.nativeview.MainActivity"
            android: screenOrientation = "portrait"
            android: theme = "@ android: style / Theme.Light.NoTitleBar"
            android: label = "Minesweeper"
             >
            <intent-filter>
                <action android: name = "android.intent.action.MAIN" />

                <category android: name = "android.intent.category.LAUNCHER" />
            </ intent-filter>
        </ activity>
    </ application>

</ manifest>
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list