虚幻Unreal - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(87评价)
价格: 3149.00元

cout << "请输入数字,结束请输入0" << endl;
    float a ;
    cin >> a;
    float total = 0;
    for (; a != 0;) {
        total += a;
        cout <<"当前结果"<< total << endl;
        cout << "请输入数字,结束请输入0" << endl;
        cin >> a;
    } //不用判断语句也是完成该题目的。。。

[展开全文]
浅唱忧伤0902 · 2020-06-26 · 0

判断是否回文字符串练习题

#include "pch.h"
#include <iostream>
#include "stdio.h"
#include "string"
using namespace std;
int main()
{
	string str;
	cin >> str;
	for (int i = 0; i < str.size() / 2; i++)
	{
		if (str[i] != str[str.size() - 1 - i])
		{
			cout << "不是回文字符串" << endl;
			return false;
		}

	}
	cout << "是回文字符串" << endl;

}

 

[展开全文]
史小墙 · 2020-05-30 · 0

1.用switvh改写下面的代码段

if(ch=='A')
 a_grade++;
else if(ch=='B')
 b_grade++;
else if(ch=='C')
 c_grade++;
else if(ch=='D')
 d_grade++;
else 
 f_grade++;

答:

switch(ch)

{

case ‘A’: a_grade++;

   break;

case ‘B’: b_grade++;

   break;

case ‘C’: c_grade++;

   break;

case ‘D’: d_grade++;

   break;

default: f_grade++;

   break;

}

2.求得20!

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	long long s=1;
	for (int i = 1; i <= 20; i++)
		s *= i;
	cout << "20!=" << s << endl;
	return 0;

}

3.求得1!+2!+3!+...+20!

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	long long s=1,a=0;
	for (int i = 1; i <= 20; i++) {
		s *= i;
		a += s;

	}
	cout << "1!+2!+3!+...+20!=" << a << endl;
	return 0;

}

4.实现函数判断一字符串是否是回文。若是回文,函数返回值为1,否则返回值0。

5.输入三个整数分别放在变量a,b,c中,然后把输入的数据从小到大顺序放到变量a,b,c中,最后输出a,b,c的值。

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	int a, b, c, m;
	cout << "请输入第一个值" << endl;
	cin >> a;
	cout << "请输入第二个值" << endl;
	cin >> b;
	cout << "请输入第三个值" << endl;
	cin >> c;
	if (a > b)
	{
		m = a; a = b; b = m;
	}
	if (a > c)
	{
		m = a; a = c; c = m;
	}
	if (b > c)
	{
		m = b; b = c; c = m;
	}
	cout << "a=" << a << endl;
	cout << "b=" << b << endl;
	cout << "c=" << c << endl;
	return 0;



}

  

[展开全文]
史小墙 · 2020-05-30 · 0

表达式1?表达式2:表达式3

//if(表达式)

{

表达式2

}

else

{

表达式3

}

[展开全文]
史小墙 · 2020-05-30 · 0

||  或运算

&& 与运算

[展开全文]
史小墙 · 2020-05-30 · 0

1.下面的代码会打印什么内容

int i;
for(int i=0;i<5;i++)
{
  cout<<i;
  cout<<endl;
}

输出结果:

0

1

2

3

4

2.下面的代码会打印什么内容

int j;
for(j=0;j<11;j+=3)
  cout<<j;
cout<<endl<<j<<endl;

输出结果:

0369

12

 

3.下面的代码会打印什么内容

int j=5;
while(++j<9)
  cout<<j++<<endl;

6

8

最后一句如果是cout<<++j<<endl;

则输出结果为

7

9

 

4.下面的代码会打印什么内容。

int k=8;
do
{
 cout<<"k ="<<k<<endl;
}
while(k++<5);
 

输出结果:

k=8

do while语句先循环一遍,再看符不符合循环条件是否跳出循环

5.编写一个打印1 2 4 8 16 32 64的for循环。

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	for (int i = 1; i <65; i *= 2)
		cout << i << " ";
	return 0;
}

6.编写一个程序,让用户输入两个整数,输出这两个整数之间所有整数的和。

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	int i, j;
	int s = 0;
	cout << "请输入第一个整数" << endl;
	cin >> i;
	cout << "请输入第二个整数" << endl;
	cin >> j;
	if (i < j)
	{
		for (; i < j + 1; i++)
		{
			s += i;
			cout << i << " ";
		}


	}
	else
	{
		for (; j < i + 1; j++)
		{
			s += j;
			cout << j << " ";
		}
	}
	cout << endl << "总和为:" << s << endl;
	return 0;



}

7.编写一个程序,让用户可以连续输入数字,每次输入数字,报告当前所有输入的和,当用户输入输入0的时候,程序结束。

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	int i, s;
	cout << "请输入值" << endl;
	cin >> i;
	s = i;
	cout << "当前和为:" << s << endl;
	while (i != 0)
	{
		cout << "请输入值" << endl;
		cin >> i;
		s += i;
		cout << "当前和为:" << s << endl;

	}
	return 0;

}

 

[展开全文]
史小墙 · 2020-05-29 · 0

a+=b;//a=a+b  -= ,*= ,/=, %=,同理

[展开全文]
史小墙 · 2020-05-28 · 0

1.创建数组actor里面有30个char

 创建数组chuck里面有13个float。

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	char actor[30];
	float chuck[13];
	return 0;

}

2.创建一个结构体糖块CandyBar,里面包含三个成员。第一个成员存储了糖块的品牌,第二个成员存储糖块的重量,第三个成员存储了糖块的卡路里。编写一个程序声明这个结构,创建一个名为snack的CandyBar变量,初始化为Moch Munch,2.3,500初始化应该声明snack的时候进行,最后程序显示snack变脸发的内容。

#include "pch.h"
#include <iostream>
#include "stdio.h"
#include <string>
using namespace std;
struct CandyBar
{
	string Logo;
	float Weight;
	int Calorie;

};
int main()
{

	CandyBar snack = { " Moch Munch" ,2.3,500 };
	cout << "Logo:" << snack.Logo << endl << "Weight:" << snack.Weight << endl << "Calorie:" << snack.Calorie << endl;



}

3.编写一个程序,然后给用户输入三次50米跑的成绩,显示次数和平均成绩。使用一个array对象来存储数据。

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	int array[3];
	float average;
	cout << "请输入第一次跑步成绩" << endl;
	cin >> array[0];
	cout << "请输入第二次跑步成绩" << endl;
	cin >> array[1];
	cout << "请输入第三次跑步成绩" << endl;
	cin >> array[2];
	average = (array[0] + array[1] + array[2]) / 3.0;
	cout << "第一次成绩:" << array[0] << endl << "第二次成绩:" << array[1] << endl << "第三次成绩:" << array[2] << endl << "平均" << average << endl;
	return 0;


}

 

[展开全文]
史小墙 · 2020-05-28 · 0

练习2修改

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	int s, d, h, m;;
	cout << "请输入秒数" << endl;
	cin >> s;
	d = s / (60 * 60 * 24);
	h = (s - d * 60 * 60 * 24) / (60 * 60);
	m = (s - h * 60 * 60 - d * 60 * 60 * 24) / 60;
	s = s - d * 60 * 60 * 24 - h * 60 * 60 - m * 60;
	cout << "其中包含" << d << "天" << h << "小时" << m << "分钟" << s << "秒" << endl;
	cin.get();
}

练习3修改

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	int m,f,p;
	cout << "请输入男生人数"<<endl;
	cin >> m;
	cout << "请输入女生人数"<<endl;
	cin >> f;
	p = (f /float (m + f))*100;
	cout << "女生比例为"<<p<<"%"<<endl;
	return 0;

}

 

[展开全文]
史小墙 · 2020-05-24 · 0

1.让用户输入自己的身高米,然后把它转换成厘米。


#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;

int main()
{
	float m;
	float cm;
	cout << "请输入身高(米)" << endl;
	cin >> m;
	cm = m * 100;
	cout << "身高(厘米)为:" << cm<<endl;
	return 0;


}

2.让用户输出秒,将其转化为多少天,多少小时,多少分钟和多少秒。

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	int s;
	float d, h, m;
	cout << "请输入秒数" << endl;
	cin >> s;
	m = s / 60; h = m / 60; d = h / 24;
	cout << "对应的天数:" << d << endl;
	cout << "对应的小时数:" << h << endl;
	cout << "对应的分钟数:" << m << endl;
	cin.get();
}

3.输入一个班级男生和女生的数量,求其女生所占百分比。

#include "pch.h"
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
	float m,f,p;
	cout << "请输入男生人数"<<endl;
	cin >> m;
	cout << "请输入女生人数"<<endl;
	cin >> f;
	p = (f / (m + f))*100;
	cout << "女生比例为"<<p<<"%"<<endl;
	return 0;

}

 

[展开全文]
史小墙 · 2020-05-24 · 0

浮点数的e表示法

3.4e数字

数字表示小数点移动位数,负数前移,正数后移

3.4e-9;//   3.4/100000000

[展开全文]
史小墙 · 2020-05-24 · 0

const int j =90;

设置其为常量,值无法修改

[展开全文]
史小墙 · 2020-05-24 · 0

字符变量的赋值

char c =‘a’;

[展开全文]
史小墙 · 2020-05-24 · 0

四个整型

short ,int, long, long long

[展开全文]
史小墙 · 2020-05-24 · 0

1.useing namespace std的作用

答:可以使用std下的相关功能

2.打印helloworld并换行

答:


#include "pch.h"
#include "stdio.h"
#include <iostream>

int main()
{
	using namespace std;
   cout << "Hello World!\n"; 
   return 0;
}

3.不使用return的情况

答:不需要返回值的情况,比如void函数。

4.让用户输入它的年龄并显示这个年龄包含多少个月。

c++中没法直接使用scanf。

#include "pch.h"
#include <iostream>
#include "stdio.h"


int main()
{
	using namespace std;
	int a, m;
	cout << "请输入你的年龄" << endl;
	cin >> a;
	m = a * 12;
	cout << "你年龄包含的月份" << endl << m << endl;
	cin.get();
	return 0;



}

 

[展开全文]
史小墙 · 2020-05-22 · 0

代码格式化

ctrl+k ctrl+f

[展开全文]
史小墙 · 2020-05-22 · 0

注释快捷键

ctrl+k  ctrl+c

取消注释

ctrl+k   ctrl+u

[展开全文]
史小墙 · 2020-05-22 · 0

using namespace std;

使用std下的功能例如cout

若没有这句。还想用std下cout的功能可使用

std::cout<<

或者开头使用

using std::cout;

[展开全文]
史小墙 · 2020-05-22 · 0

cout<<" "表示输出字符串变量值。

cout<<' '表示是字符变量值,字母的本质也是数字。

int  a=10;

cout<<"a";//输出为问 字符a;

cout<<a;//输出为10;

cout<<'a' ;//输出为65;

cout<<endl;//换行

一般情况下,来cin自动跳过输入的空格。如果你要把键盘上输入的每个字符自,包括空格和回车键都作为一个输入字符给字符型变量时,必百须使用函数cin.get()。

[展开全文]
史小墙 · 2020-05-22 · 0

注释快捷键ctrl+K   ctrl+C 

取消注释快捷键ctrl+K   ctrl+U

[展开全文]
Eaven · 2020-03-04 · 0