第14周项目5-数组大折腾

来源:互联网 发布:用不到算法 编辑:程序博客网 时间:2024/06/05 13:31
/* * 程序的版权和版本声明部分 * Copyright (c)2013, 烟台大学计算机学院学生 * All rightsreserved. * 文件名称: fibnacci.cpp * 作    者: 孔云 * 完成日期:2013年11月27日 * 版 本 号: v1.0 * 输入描述:无 * 问题描述:使用整型数组,将元素值加倍保存在数组中。 * 程序输出:由前往后输出改变的元素值;* 由后往前输出改变的元素值;* 输出数组中大于100的数;* 输出数组中下标为3的倍数的元素值。 * 问题分析:使用数组编程序。 */  #include <iostream>#include <cstdio>支持重定向using namespace std;int main(){    int a[10] {901,508,63,15,26,350,24,16,13,19};    int i=0;//freopen("input.txt","r",stdin);    cout<<"由前往后数组中加倍的元素值为:";    for(i=0; i<10; i++)    {        if(i%5==0)cout<<endl;        cout<<2*a[i]<<" ";    }    cout<<endl;    cout<<"由后往前数组中加倍的元素值为:"<<endl;    for(i=9; i>=0; i--)    {        cout<<2*a[i]<<" ";        if(i%5==0)cout<<endl;    }    cout<<"数组中大于100的数:"<<endl;    for(i=0; i<10; i++)        if(2*a[i]>100)        {            cout<<2*a[i]<<" ";            if((i+1)%5==0)cout<<endl;        }    cout<<endl;    cout<<"数组中下标为3的倍数的元素值:";    for(i=0; i<10; i++)        if(i%3==0)        {            if(i%5==0)cout<<endl;            cout<<2*a[i]<<" ";        }    return 0;}

心得体会:做事总有困难,但是方法总比困难多,遇到困难不仅找方法更应该用最简便的方法解决奋斗

原创粉丝点击