C++高手请进帮忙写个代码,十万火急!!!

###注意:请运行程序无错误后再给我答案,这是个很重要的作业,谢谢。。。以下是题目:
1.Write a program that stores and prints ONE HUNDRED (100) integers in a 2D (twodimensional)
array of TEN (10) rows and TEN (10) columns. Fill the array with random integers
in between 1 to 100. Calculate how many odd values and even values are there in the array. Note
that the random integers should very be varied every time the program is run.

// sgjv.cpp : Defines the entry point for the console application.
//
// 1.Write a program that stores and prints ONE HUNDRED (100) integers in a 2D (twodimensional)
// array of TEN (10) rows and TEN (10) columns. Fill the array with random integers
// in between 1 to 100. Calculate how many odd values and even values are there in the array. Note
// that the random integers should very be varied every time the program is run.
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
using namespace std;
int main(void)
{
int iarray[10][10];
int i,j;
int odd=0,even=0;
srand(time(NULL)); // 去当前时间做种子
for (i=0;i<10;i++)
{
for (j=0;j<10;j++)
{
iarray[i][j] = rand()%99+1;
}
}
for (i=0;i<10;i++)
{
for (j=0;j<10;j++)
{
if (iarray[i][j]%2 == 0)
{
even++;
}
else
{
odd++;
}

}
}
for (i=0;i<10;i++)
{
for (j=0;j<10;j++)
{
cout.width(5); //设置输出宽度5
cout.setf(ios::left); //设置左对齐输出
cout<<iarray[i][j];
}
cout<<endl;
}
cout<<"odd NO::"<<odd<<endl; //输出奇数个数
cout<<"even NO::"<<even<<endl;// 输出偶数个数
return 0;
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-03-24
兄弟给分哦!
VC6下跑莫问题!
#include "iostream.h"
#include "time.h"
#include "stdlib.h"

#define MAX_ROW 10
#define MAX_LINE 10

/*!
this function will set seed by system time to
generate different number.
*/
void setSeed()
{
srand((unsigned)time(NULL));
}

/*!
this function will create random array integer.
\return bool false(operate failure)|true(successful)
*/
bool createRandom(int (*pParam)[MAX_LINE])
{
if (!pParam)
{
cout << "input pointer is null" << endl;
return false;
}

setSeed();

for(int i = 0; i < MAX_ROW; i++)
{
for(int j = 0; j < MAX_LINE; j++)
{
pParam[i][j] = rand()%100 + 1;
}
}

return true;

}

/*!
entrance of application.
*/
int main(int argc, char **argv)
{
int arrayNum[MAX_ROW][MAX_LINE] = {0};

cout << "----------------create random------------------"<<endl;
if(!createRandom(arrayNum))
{
cout << "create random failure!\n" << __LINE__ << endl;
return -1;
}
cout << "----------------create succesful------------------" << endl;

int iRet = 0;

cout << "display random array:\n";
for(int i = 0; i < MAX_ROW ; i++)
{
for(int j = 0; j < MAX_LINE; j++)
{
arrayNum[i][j]%2 ? iRet++ : 0;
cout << arrayNum[i][j] << " " ;
}

cout << endl;
}

cout << "the number of odd in array is :" << iRet <<endl;

return 0;
}
第2个回答  2009-03-23
这么简单的题目,还是自己完成比较好
第3个回答  2009-03-23
自己写
第4个回答  2009-03-23
像这样简单的问题都不自己动手做?

C++高手请进帮忙写个代码,十万火急!!!
cout<<"even NO::"<<even<<endl;\/\/ 输出偶数个数 return 0;}

C++问题,高手请进!!!急!!!
include <iostream> include <algorithm>\/\/这是用于排序的库函数 include <ctime> using namespace std;int main(){ srand((unsigned)time(0));\/\/时间种子 int N;int a[100],b[100];cin>>N;for(int i=0;i<N;i++)a[i]=rand()%1000+1;\/\/产生随机数 sort(a,a+N);\/\/这个用来排序...

c++ 高手请进,我只有这些分了,谢了,急急急急急!!!
include <stdlib.h> define LEN 256 struct node { char str[LEN]; \/\/字符串 struct node* next;\/\/指向下个结构 };int main(){ struct node head_node;struct node* p = &head_node;struct node* q;int i;scanf("%s", head_node.str);\/\/输入第一个字符串 for (i=0;i<100000 - ...

拜求C++高手,有好心编程高手帮帮忙,谢谢了!!
include "iostream.h"class Array { private:int a[4][4];public:Array(int a1[][4],int n){ for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ a[i][j]=a1[i][j];} } } void xuanzhaun()\/\/:实现对方阵a进行顺时针90度的旋转。{ int temp[4][4];for(int i=0;i...

(c++)高手请进...帮我转code!!!
int iStarOfNumber = 0; \/\/输出星号"*"个数控制 while (iNumberOfStart != iStarOfNumber){ cout<<"-*";\/\/print star iStarOfNumber++;} cout<<endl;return TRUE;} ERRORCODE Prompt(){ \/\/上边框的打印 PrintStar(MAX_OF_STAR_NUMBER);\/\/输出欢迎词 cout<<"Welcome to the Students ...

高分求助!!十万火急!!C++万年历 求高手帮忙进行数据封装!!
{cout<<"请输入月份: ";cin>>month;if(f==3){ cout<<"请输入日期: ";cin>>day;while(mon<month) totaldays+=monthdays[mon++-1];if(month>2&&flag) totaldays++;monthweek=(totaldays+1)%7;totaldays=totaldays+day;week=totaldays%7;for(int f(week);f>0;f--) ...

请懂C++的高手帮个忙~!
(教皇格利高里十三世丢掉了十天--1582年十月5到14,改进了 闰年算法--400年97闰).\/ void cal_mjd(int mn,double dy,int yr,double *mjd){ static double last_mjd, last_dy;static int last_mn,last_yr;int b,d,m,y;long c;if(mn==last_mn&&yr==last_yr&&dy==last_dy){ mjd=last...

一道C++程序,高手帮忙看一下!万分感谢!送10分以表感谢!
k++){ j++;if(k>30) k=1;} while(a[k]!=0){ k++;if(k>30) k=1;} a[k++]=1;if(k>30) k=1;\/\/n++;} 这是程序内核所在,循环15次每次剔除一人,for(j=1;a[k]==0&&j<9;k++)循环中又把第九个数赋为1表示剔除,if(k>30) k=1; 保证人数在30内循环!由此可得!

高手请进!c++编程急需!重金悬赏。。。请发邮箱708891089@qq.com...
int year;int month;int day;};int days(struct date day){ static int day_tab[2][13]= {{0,31,28,31,30,31,30,31,31,30,31,30,31,}, \/* 平均每月的天数 *\/ {0,31,29,31,30,31,30,31,31,30,31,30,31,},};int i,lp;lp=day.year%4==0&&day.year%100!=0||day....

C++问题,请各位高手赐教
同意 希声和寡 的答,简单精辟 补充一句,这是最有效的交换两数的值的代码。

相似回答
大家正在搜