c++输入十个整数,最小的与第一个交换,最大的与最后一个交换,要求用指针
能不能帮我看看我这个哪错了。。max函数我想返回最大的那个数的指针。。然后通过指针给数组赋值。。#include"stdafx.h"#include<iostream>#...
能不能帮我看看我这个哪错了。。max函数我想返回最大的那个数的指针。。然后通过指针给数组赋值。。
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
void max(string *p1, string *p2, string *p3);
void putin(int *pointer[]);
void putout(int *pointer[]);
void zhixing(int *pointer[]);
int *max(int *pointer[]);
int *min(int *pointer[]);
int _tmain(int argc, _TCHAR* argv[])
{
int a[10];
int * pointer[10];
for (int i = 0; i < 10; i++){
pointer[i] = &a[i];
}
putin(pointer);
zhixing(pointer);
putout(pointer);
}
void putin(int *pointer[]){
for (int i = 0; i<10; i++){
cin >> *pointer[i];
}
}
void zhixing(int *pointer[]){
int *da, *xiao;
int temp;
da = max(pointer);
xiao = min(pointer);
temp = *pointer[0];
*pointer[0] = *xiao;
*xiao = temp;
temp = *pointer[9];
*pointer[9] = *da;
*da = temp;
}
int *max(int *pointer[]){
int *da=pointer[0];
for (int i = 0; i < 9; i++){
if ((*pointer[i]) < (*pointer[i + 1])){
da = pointer[i + 1];
}
}
return da;
}
int *min(int *pointer[]){
int *xiao=pointer[0];
for (int i = 0; i < 9; i++){
if ((*pointer[i])>(*pointer[i + 1])){
xiao = pointer[i+1];
}
}
return xiao;
}
void putout(int *pointer[]){
for (int i = 0; i<10; i++){
cout<< *pointer[i]<<',';
}
} 展开
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
void max(string *p1, string *p2, string *p3);
void putin(int *pointer[]);
void putout(int *pointer[]);
void zhixing(int *pointer[]);
int *max(int *pointer[]);
int *min(int *pointer[]);
int _tmain(int argc, _TCHAR* argv[])
{
int a[10];
int * pointer[10];
for (int i = 0; i < 10; i++){
pointer[i] = &a[i];
}
putin(pointer);
zhixing(pointer);
putout(pointer);
}
void putin(int *pointer[]){
for (int i = 0; i<10; i++){
cin >> *pointer[i];
}
}
void zhixing(int *pointer[]){
int *da, *xiao;
int temp;
da = max(pointer);
xiao = min(pointer);
temp = *pointer[0];
*pointer[0] = *xiao;
*xiao = temp;
temp = *pointer[9];
*pointer[9] = *da;
*da = temp;
}
int *max(int *pointer[]){
int *da=pointer[0];
for (int i = 0; i < 9; i++){
if ((*pointer[i]) < (*pointer[i + 1])){
da = pointer[i + 1];
}
}
return da;
}
int *min(int *pointer[]){
int *xiao=pointer[0];
for (int i = 0; i < 9; i++){
if ((*pointer[i])>(*pointer[i + 1])){
xiao = pointer[i+1];
}
}
return xiao;
}
void putout(int *pointer[]){
for (int i = 0; i<10; i++){
cout<< *pointer[i]<<',';
}
} 展开
1个回答
展开全部
// 百度知道一.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
void max(string *p1, string *p2, string *p3);
void putin(int *pointer[]);
void putout(int *pointer[]);
void zhixing(int *pointer[]);
int *max(int *pointer[]);
int *min(int *pointer[]);
int _tmain(int argc, _TCHAR* argv[])
{
int a[10];
int *pointer[10];
for (int i = 0; i < 10; i++)
{
pointer[i] = &a[i];
}
putin(pointer);
zhixing(pointer);
putout(pointer);
return 0;
}
void putin(int *pointer[])
{
for (int i = 0; i<10; i++)
{
cin >> *pointer[i];
}
}
void zhixing(int *pointer[])
{
int *da, *xiao;
int temp;
da = max(pointer);
xiao = min(pointer);
temp = *pointer[0];
*pointer[0] = *xiao;
*xiao = temp;
temp = *pointer[9];
*pointer[9] = *da;
*da = temp;
}
int *max(int *pointer[])
{
int *da = pointer[0];
for (int i = 0; i < 9; i++)
{
//修改的地方
/*if ((*pointer[i]) < (*pointer[i + 1]))
{
da = pointer[i + 1];
} */
if (*da<(*pointer[i]))
{
da = pointer[i];
}
}
return da;
}
int *min(int *pointer[])
{
int *xiao = pointer[0];
for (int i = 0; i < 9; i++)
{
//修改的地方
/*if ((*pointer[i])>(*pointer[i + 1]))
{
xiao = pointer[i + 1];
} */
if (*xiao>(*pointer[i]))
{
xiao = pointer[i];
}
}
return xiao;
}
void putout(int *pointer[])
{
for (int i = 0; i<10; i++)
{
cout << *pointer[i] << ',';
}
}
最大最小函数的写法不应该是这样吧
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
void max(string *p1, string *p2, string *p3);
void putin(int *pointer[]);
void putout(int *pointer[]);
void zhixing(int *pointer[]);
int *max(int *pointer[]);
int *min(int *pointer[]);
int _tmain(int argc, _TCHAR* argv[])
{
int a[10];
int *pointer[10];
for (int i = 0; i < 10; i++)
{
pointer[i] = &a[i];
}
putin(pointer);
zhixing(pointer);
putout(pointer);
return 0;
}
void putin(int *pointer[])
{
for (int i = 0; i<10; i++)
{
cin >> *pointer[i];
}
}
void zhixing(int *pointer[])
{
int *da, *xiao;
int temp;
da = max(pointer);
xiao = min(pointer);
temp = *pointer[0];
*pointer[0] = *xiao;
*xiao = temp;
temp = *pointer[9];
*pointer[9] = *da;
*da = temp;
}
int *max(int *pointer[])
{
int *da = pointer[0];
for (int i = 0; i < 9; i++)
{
//修改的地方
/*if ((*pointer[i]) < (*pointer[i + 1]))
{
da = pointer[i + 1];
} */
if (*da<(*pointer[i]))
{
da = pointer[i];
}
}
return da;
}
int *min(int *pointer[])
{
int *xiao = pointer[0];
for (int i = 0; i < 9; i++)
{
//修改的地方
/*if ((*pointer[i])>(*pointer[i + 1]))
{
xiao = pointer[i + 1];
} */
if (*xiao>(*pointer[i]))
{
xiao = pointer[i];
}
}
return xiao;
}
void putout(int *pointer[])
{
for (int i = 0; i<10; i++)
{
cout << *pointer[i] << ',';
}
}
最大最小函数的写法不应该是这样吧
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询