在c ++中,如何显示线性系列的所有数字?

时间:2016-09-30 16:35:34

标签: c++

这是我到目前为止所拥有的。我可以显示该系列的第一个,第二个和最后一个数字。

# Protects .htaccess
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>

# Protects config file
<files wp-config.php>
order allow,deny
deny from all
</files>

# Block the include-only files.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>

# disable directory browsing
Options All -Indexes

# Block WordPress xmlrpc.php requests
<Files xmlrpc.php>
Order allow,deny
Deny from all
</Files>

我尝试了'for'循环,但我有同样的问题;我无法显示c数量,因此我必须做出

int main()
{   
  int a,b,c;
  cout<<"The first number: "<<endl;
  cin>>a;
  cout<<"The difference: "<<endl;
  cin>>b;
  cout<<"How many numbers are in the series: "<<endl;
  cin>>c;

  cout<<"The numbers of the linear series are: "<<endl;
  cout<<a<<endl; 
  cout<<a+b<<endl; cout<<a+b*(c-1)<<endl;

  return 0;
}

等等。如果系列只有2个元素,这甚至都没有意义。

如何显示线性系列的第一个和最后一个数字之间的数字?是否必须使用'string'做一些事情?还有,有办法做

这样的事情
cout<<a+b; cout<<a+b*2; cout<<a+b*3;

我知道这段代码没有意义,但希望你明白这个想法

1 个答案:

答案 0 :(得分:1)

在构建线性序列时,所有数字的格式都为f(n) = a + b*n,您可以使用for循环将其设置为优势,如您所提到的那样。您应该能够从以下伪代码中找出它:

Output "The numbers of the linear series are: "
For i = 0 to c-1
    Output a + b*i
Next i
相关问题