Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi, i need avg of two greater nos, so kindly help me.
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Data;
 
public partial class HomePage : System.Web.UI.Page
{
    adminDB admDB;
    protected void Page_Load(object sender, EventArgs e)
    {
        txtRegNo.Focus();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
       
 
        //Retrive Marks
        try
        {
            DataSet ds = new DataSet();
            admDB = new adminDB();
            ds = admDB.RetriveIAMArks1(txtRegNo.Text, txtIA1.Text, ddlBranch.Text);
            if (ds.Tables[0].Rows.Count > 0)
            {
                lblmsg.Visible = false;
                gvNames.Visible = true;
                gvNames.DataSource = ds;
                gvNames.DataBind();
                lbl1.Text= ds.Tables[0].Rows[0][7].ToString();
            }
            else
            {
                gvNames.Visible = true;
                lblmsg.Text = "No results found!";
            }
 
            admDB = new adminDB();
            ds = admDB.RetriveIAMArks2(txtRegNo.Text, txtIA2.Text, ddlBranch.Text);
            if (ds.Tables[0].Rows.Count > 0)
            {
                lblmsg.Visible = false;
                gvNames.Visible = true;
                gvNames.DataSource = ds;
                gvNames.DataBind();
                lbl2.Text = ds.Tables[0].Rows[0][7].ToString();
            }
            else
            {
                gvNames.Visible = true;
                lblmsg.Text = "No results found!";
            }
 
            admDB = new adminDB();
            ds = admDB.RetriveIAMArks3(txtRegNo.Text, txtIA3.Text, ddlBranch.Text);
            if (ds.Tables[0].Rows.Count > 0)
            {
                lblmsg.Visible = false;
                gvNames.Visible = true;
                gvNames.DataSource = ds;
                gvNames.DataBind();
                lbl3.Text = ds.Tables[0].Rows[0][7].ToString();
            }
            else
            {
                gvNames.Visible = true;
                lblmsg.Text = "No results found!";
            }
        }
        catch (Exception ex)
        {
            lblmsg.Text = ex.ToString();
        }
 
        try
        {
            DataSet ds = new DataSet();
            admDB = new adminDB();
            ds = admDB.ViewAssignmentbyRegNo(txtRegNo.Text, ddlBranch.Text);
            if (ds.Tables[0].Rows.Count > 0)
            {
                lblmsg.Visible = false;
                gvNames.Visible = true;
                Label7.Visible = true;
                gvNames.DataSource = ds;
                gvNames.DataBind();
 
                int ia1, ia2, 1a3;
                decimal avg;
                ia1 = Convert.ToInt16(lbl1.Text);
                ia2 = Convert.ToInt16(lbl2.Text);
                
                avg = (ia1 + ia2 + ia3 ) / 2;
                lblavg.Text = avg.ToString();
            }
            else
            {
                lblmsg.Visible = true;
                gvNames.Visible = false;
                lblmsg.Text = "No results found!";
            }
        }
        catch (Exception ex)
        {
            lblmsg.Text = ex.ToString();
        }
 
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("HomePage.aspx");
    }
}
Posted 16-Nov-12 17:16pm
Edited 16-Nov-12 17:45pm
v2
Comments
Sergey Alexandrovich Kryukov at 17-Nov-12 0:29am
   
"Nos"?
--SA
Nelek at 17-Nov-12 5:18am
   
Nos = Numbers
Sergey Alexandrovich Kryukov at 17-Nov-12 21:25pm
   
I could guess, but I hate do take such kind of guess. Believe of not, I consider such abbreviations like a kind of rudeness...
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

 
int[] intArray = new int[3] {ia1,ia2,ia3 }; //add all three value in intarray

Array.Sort(intArray); // sort them in ascending order 

avg = (intArray [1]+intArray [2]) / 2; // add largest and second largest no and divide it by 2

lblavg.Text = avg.ToString(); // show them in label
 
i haven't tested it..
but hoping it will run...
 
[edit]code block added[/edit]
  Permalink  
v5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi
 
  List<int> lstInt = new List<int>();
            lstInt.Add(10);
            lstInt.Add(6);
            lstInt.Add(14);
       
            lstInt.Sort();
            lstInt.Reverse();
            double x = lstInt.Take(2).Average();
  Permalink  
v2
Comments
Dominic Abraham at 18-Nov-12 1:30am
   
If the solution is helpful, please mark it as answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 504
1 Gihan Liyanage 298
2 RyanDev 250
3 Sergey Alexandrovich Kryukov 223
4 Richard Deeming 195
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,771
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100