数组,表示数组是升序还是不升序

时间:2016-03-19 23:56:22

标签: c++ arrays

所以问题是弄清楚数组是升序还是不升序意味着如果数组是2,3,4,6它会显示是升序,如果它是3,2,5,6它会显示没有不提升。

我似乎无法让程序显示0表示不提升,我知道问题是在for循环或if语句的某处,但我不知道如何解决它

namespace Portal.Controllers
{  
public class MyEventController : Controller
{      
    [HttpPost]
    public ActionResult Save(InputEvent y)
    {            
        MySqlConnection conn = new MySqlConnection("mydbstring");
        string myTitle = y.title;
        string myAddress = y.address;

        conn.Open();                         

        MySql.Data.MySqlClient.MySqlCommand comm = conn.CreateCommand();
        comm.CommandText = "INSERT INTO event(title, address) VALUES(@title, @address)";

        //comm.Parameters.AddWithValue("@title", myTitle);
        //comm.Parameters.AddWithValue("@address", myAddress);

        comm.Parameters.AddWithValue("@title", "test_title");
        comm.Parameters.AddWithValue("@address", "test_address");
        comm.ExecuteNonQuery();

        conn.Close();

        return View();
    }        
}
}

2 个答案:

答案 0 :(得分:1)

您的问题在升序功能中,您在第一次迭代后返回1。为了确定数字序列是否在升序,您必须遍历所有数字。但是,如果您发现任何时候都没有提升的号码,那么您可以立即返回0。如果你安全地迭代所有这些而不返回0,那么你知道序列是递增的

$studentsQuery = \FeeModal::query();
$studentsFee = $studentsQuery->groupBy('main_campus_id', 'session_id', 'class_info_id', 'section_id', 'stage_id')
                ->selectRaw('count(student_id) as student_strength,SUM(IF(paid_amount>0,1,0)) as submit_students,SUM(IF(paid_amount=0,1,0)) as not_submit_students, sum(paid_amount) as submit_amount')
                ->with('sessionMode', 'section',  'classInfo', 'stage')->get();

dd(count($studentsFee). ' Records' );

答案 1 :(得分:0)

int ascending(int x[], int n)
{
    int i = 0;
    Do
    {
        if(x[i]> x[i + 1])
        return 0;
        i++;
    } while (i < n-1);

    return 1;
}