数字输出来和个数,我都不会,能否给我一个模板,这个最近才学,我很多不会。
如有帮助,望点击我回答右上角【灰色采纳】按钮支持一下。
#include <iostream>
using namespace std;
int main()
{
int n, a1, a2, b1, b2, m = 0, count = 1;
//cout << "1000-2000之间满足条件的数有:" << endl;
for(n = 1000; n <= 2000; n++)
{
a1 = n / 1000;
a2 = (n - a1 * 1000) / 100;
b1 = n % 100 / 10;
b2 = n % 10;
if(a1 + a2 == b1 + b2)
{
m = count ++;
cout << n << " "; //注意此处改为了空格
}
}
cout << endl;
//cout << endl << "一共有" << m << "个" << endl;
cout << m << endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n=0;
for(int i=1000;i<=2000;i++)
{
int a = i%100;
int b = i/100;
int c = a%10;
int c1 = a/10;
int d = b%10;
int d1 = b/10;
if(c+c1 == d+d1)
{
cout<<i<<" ";
n++;
}
}
cout<<endl;
cout<<n<<endl;
return 0;
}
m的值好像没有累加