第十三周项目一(3) 按条件输出数据

来源:互联网 发布:淘宝上架后用不用管了 编辑:程序博客网 时间:2024/05/22 03:51

问题及代码:

/** Copyright (c) 2014, 烟台大学计算机学院* All rights reserved.* 文件名称:Project4.cpp* 作    者:宋健* 完成日期:2014年11月25日* 版 本 号:v1.0** 问题描述:创建数组并输出* 输入描述:* 程序输出:*/#include <iostream>using namespace std;int main( ){    int a[16]= {13,45,89,332,54,221,90,723,65,45,123,47,96,48,187,0};    int i;    cout<<"数组中,元素值为3的倍数的数是:"<<endl;    for(i=0; i<16; i++)    {        if(a[i]%3==0)            cout<<"a["<<i<<"] "<<a[i]<<endl;    }    cout<<"下标为3的倍数的元素值是:"<<endl;    for(i=0; i<16; i++)    {        if(i%3==0)            cout<<"a["<<i<<"] "<<a[i]<<endl;    }    return 0;}


 

运行结果:

知识点总结:

按条件筛选需要将数组从头开始重新过一遍,然后把符合条件的输出

学习心得:

数组的长度与能够存储的数据需要注意。

0 0
原创粉丝点击