>radius;Рcircumference=2*PI*radius; Рarea=PI*radius*radius; Рcout<<"circumference="< >radius;Рcircumference=2*PI*radius; Рarea=PI*radius*radius; Рcout<<"circumference="<

全文预览

人民邮电大学出版的C++课后答案

上传者:叶子黄了 |  格式:doc  |  页数:42 |  大小:0KB

文档介绍
main() Р{Рdouble radius,circumference,area; Рcout<<"Please input radius"<Рcin>>radius;Рcircumference=2*PI*radius; Рarea=PI*radius*radius; Рcout<<"circumference="<<circumference<Рcout<<"area="<<area<Р} Р3 . 用 new 运算符为一个包含 20 个整数的数组分配内存, 输入若干个值到数组中, 分别统计其中正数和负数的个数, 输出结果, 再用 delete 运算符释放动态内存空间。Р【参考答案】/*biancheng2_3.cpp : 动态数组空间的管理和操作*/Р#include Рusing namespace std; Рvoid main() Р{ Рint num,positive=0,negative=0; Рint *p=new int[20]; Рcout<<"Please intput the number you want use of array:\n"; Рcin>>num; Рif (num>20) Р{ Рcout<<"number too large,exit."; Рreturn; Р} Рfor (int i=0;iРcin>>p[i]; Рfor (i=0;iРif (p[i]>0) positive++; Рelse if (p[i]Рcout<<"There are "<<num<<" figures,\n"; Рcout<<positive<<" of them are positive numbers,\n"; Рcout<<negative<<" of them are negatives.\n"; Рdelete []p; Р}

收藏

分享

举报
下载此文档