新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

使用c++实现乘法表输出

看过很多自学C++的朋友们,都是从简单程序入手,这里我分享一下我入门的几个简单的程序。

专注于为中小企业提供网站制作、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业宿豫免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了超过千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。


1.使用c++实现乘法表输出

#define _crt_secure_no_warnings 1
#include
#include//为了使用setw来实现输出占位
using namespace std;
void multiplicationtable()//乘法表
{
    int i, j,n;
    cin >> n;
    for (i = 1; i < n+1; i++){
        for (j = 1; j < i + 1; j++){
            cout << setw(5) << i << '*' << j << '=' << i*j;
        }
        cout << endl;
    }
}
int main()
{
    cout << "multiplicationtable :" << endl;
    multiplicationtable();
    system("pause");
    return 0;
}

2.判断1000-2000年的闰年

#define _crt_secure_no_warnings 1
#include
using namespace std;
void leapyear(int i)//判断闰年
{
    if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0){//闰年判断需满足可被4整除以及可被400整除
        cout <> k;
    leapyear(k);
    system("pause");//使程序暂停显示结果
    goto And;//使用goto语句使程序可以多次实现功能
    return 0;

-----

}

3.输出100至200的素数

#define _crt_secure_no_warnings 1
#include
#include
using namespace std;
void primenumber()//素数输出
{
    int i, j,cut=0;
    for (i = 101; i < 200; i+=2){
        for (j = 2; j <= sqrt(i); j++){
            if (i%j == 0)
                break;
        }
        if (sqrt(i) < j)
            cut++;
            cout << setw(5) << i;
    }
    cout <

相信每个初学者对于C语言中简单的代码,在移植至c++环境下运行都有很多的疑问,可以参考以上3段代码。


文章名称:使用c++实现乘法表输出
新闻来源:http://www.wjwzjz.com/article/jjgjpg.html
在线咨询
服务热线
服务热线:028-86922220
TOP