c++编写一个程序读入10个数.输出其中不同的数(即如果一个数出现多次,只打印一次)#include using namespace std;int main(){int numbers[10];int size = 0;for (int i = 0; i < 10; i++) {// Read and store numbers in an array if
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/12 03:47:46
![c++编写一个程序读入10个数.输出其中不同的数(即如果一个数出现多次,只打印一次)#include using namespace std;int main(){int numbers[10];int size = 0;for (int i = 0; i < 10; i++) {// Read and store numbers in an array if](/uploads/image/z/14761351-55-1.jpg?t=c%2B%2B%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AA%E7%A8%8B%E5%BA%8F%E8%AF%BB%E5%85%A510%E4%B8%AA%E6%95%B0.%E8%BE%93%E5%87%BA%E5%85%B6%E4%B8%AD%E4%B8%8D%E5%90%8C%E7%9A%84%E6%95%B0%28%E5%8D%B3%E5%A6%82%E6%9E%9C%E4%B8%80%E4%B8%AA%E6%95%B0%E5%87%BA%E7%8E%B0%E5%A4%9A%E6%AC%A1%2C%E5%8F%AA%E6%89%93%E5%8D%B0%E4%B8%80%E6%AC%A1%EF%BC%89%23include+using+namespace+std%3Bint+main%28%29%7Bint+numbers%5B10%5D%3Bint+size+%3D+0%3Bfor+%28int+i+%3D+0%3B+i+%3C+10%3B+i%2B%2B%29+%7B%2F%2F+Read+and+store+numbers+in+an+array+if)
c++编写一个程序读入10个数.输出其中不同的数(即如果一个数出现多次,只打印一次)#include using namespace std;int main(){int numbers[10];int size = 0;for (int i = 0; i < 10; i++) {// Read and store numbers in an array if
c++编写一个程序读入10个数.输出其中不同的数(即如果一个数出现多次,只打印一次)
#include
using namespace std;
int main()
{
int numbers[10];
int size = 0;
for (int i = 0; i < 10; i++) {
// Read and store numbers in an array if it is new
cout > value;
bool isInArray = false; //引入了一个可以改变的布尔变量,用于判断第一个数自动输入数组里面
for (int j = 0; j < size; j++)
if (*(numbers + j) == value) {
isInArray = true;
break;
}
if isInArray) {
*(numbers + size) = value;
size++;
}
}
for (int i = 0; i < size; i++)
cout
c++编写一个程序读入10个数.输出其中不同的数(即如果一个数出现多次,只打印一次)#include using namespace std;int main(){int numbers[10];int size = 0;for (int i = 0; i < 10; i++) {// Read and store numbers in an array if
numbers是数组名,也就是这个数组首元素的地址.numbers+j就是第j个元素的地址,而*(numbers+j)就是第j个元素的值.其中*是取后面的指针指向的内存中的数据的意思,而指向+整型数是指针向后移动整型数那么多个元素的地址.比如这里int numbers[10]={3,6,2...};那么numbers+2就指向了2,而*(numbers+2)就是2.