Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how can we sum the numbers from 1 to 100 using asp.net. I have tried using datalist.. but I was unabl to get it..
Posted

Just a thought.
Sum from 1 to n = n*(n+1)/2


So here you can simply use 100*(100+1)/2, nothing fancy.
 
Share this answer
 
You can try this
int Total=0;
for(i=1;i<=100;i++)
{
    Total=Total+i;
}
Response.Write("Total = "+Total.ToString());
 
Share this answer
 
C#
int i=1;
int total=0;
while(i<=100)
{
     total=total+i;
     i++;
}
response.write("Ans :"+total.ToString());
 
Share this answer
 
v6

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900