c++基础复习之求平均值以及字符串输入输出
来源:互联网 发布:流程图绘制软件 编辑:程序博客网 时间:2024/06/05 14:20
1. 整数表达式(求平均值)
- 程序要求:求输入的正整数的平均值,但是当输入为负数时,提示输入有误,重新输入。代码如下:
/************************* > Author: wcyd > Mail: wuc201609@163.com > Created time: 2017.8.14*************************/#include<iostream>using namespace std;int main(){ int x, sum = 0; float average, n = 0; cout << "please enter some numbers :"<< endl; while( cin >> x) { if(x < 0) cout << "The number is below zero! please enter another :"<< endl; else { sum += x; n++; } } average = sum/n; cout << "This numbers average is: "<< average <<endl; return 0;}
2. 字符串的简单输入输出
- string类型支持长度可变的的字符串,c++标准库将负责管理与存储字符相关的内存,以及提供各种有用的操作。与其他的标准库类型一样,使用string类型对象,必须包含相关头文件。代码如下:
/************************* > Author: wcyd > Mail: wuc201609@163.com > Created time:2018.8.14*************************/#include<iostream>#include<string>using namespace std;int main(){ string name; string response; cout << "Hello, what's you name?"<<endl; cin >> name; cout << "How are you!"<<endl; cin >> response; cout << name <<" , nice to meet you, see you again."<<endl; return 0;}
阅读全文
1 0
- c++基础复习之求平均值以及字符串输入输出
- C语言求平均值
- C语言求平均值
- 1054. 求平均值 (字符串处理)
- python基础复习之数字和字符串
- SQL求平均值以及总和的写法
- 1054. 求平均值 (20) 字符串处理
- C语言基础—字符串输入输出函数puts和gets
- C/C++求两个数的平均值
- C/C++学习:求平均值函数
- C语言 java 求整形数组平均值
- C语言 求一串数字的平均值
- C语言基础复习之指针
- 用%c输入输出字符串
- C字符串输入输出
- C/C++ 字符串输入输出
- C 字符串的输入输出
- C语言 输入输出字符串
- px、em、rem、%、vw、wh、vm等单位有什么区别?
- 【Tomcat】-- Tomcat + Nginx反向代理https和wss并解决获取客户端真实IP、域名、协议、端口
- jenkins之使用git
- C++String fing函数
- 使用tcollector及使用过程中遇到的错误
- c++基础复习之求平均值以及字符串输入输出
- Git的基本操作
- 猜数游戏的一个C++实现
- SSM(SpringMVC Spring Mybatis)三大框架从零开始搭建实例
- c# 控件多屏显示全屏功能
- 如何在软件UI设计中运用格式塔心理学5项法则?
- UVA-10391 二分
- 关于.NET 垃圾回收机制
- 机器学习学习笔记 2、概率论