is this the same??

The problem is to print odd numbers from 1-100 and its sums.
i got the problem.
im just asking if it will be the same when i change something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
using namespace std;

int main()
{
	int odd=0,ctr;
	for(ctr=0;ctr<100;ctr++)
	{
		if (ctr%2==1)
		{
			cout<<ctr<<"\n";
		}
		else
			continue;
	}
	for (ctr=0;ctr<100;ctr++)
	{
		if (ctr%2==1)
			odd=odd+ctr;
	}
	cout<<"The sum of odds is: "<<odd<<"\n";
	return 0;
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
using namespace std;

int main()
{
	int odd=0,ctr;
	for(ctr=0;ctr<100;ctr++)
	{
		if (ctr%2==1)
		{
			cout<<ctr<<"\n";
                        odd=odd+ctr;
		}
		else
			continue;
	}
	
	cout<<"The sum of odds is: "<<odd<<"\n";
	return 0;
}


Im just not at a place where theres a compiler to test if it works...

help will be much appreciated~
yeah that will work. Though, You can remove the

1
2
else
	 continue;


because it will still loop around even without that.
Last edited on
Thx man~

now i can be relieved~
you're welcome.
Topic archived. No new replies allowed.