0% found this document useful (0 votes)
84 views1 page

Find Sum of Even Number

This code defines a method to find the sum of all even numbers up to a given integer limit. It takes the limit as a parameter, uses a for loop to iterate from 1 to the limit, checks if each number is even using the modulo operator, adds any even numbers to a running sum variable, and returns the final sum. The main method prompts the user for the limit, calls the Even method, and prints the result.

Uploaded by

Rajthilak24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views1 page

Find Sum of Even Number

This code defines a method to find the sum of all even numbers up to a given integer limit. It takes the limit as a parameter, uses a for loop to iterate from 1 to the limit, checks if each number is even using the modulo operator, adds any even numbers to a running sum variable, and returns the final sum. The main method prompts the user for the limit, calls the Even method, and prints the result.

Uploaded by

Rajthilak24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

4.

Define a method to find sum of even numbers up to given limit


Code:
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Evensum
{
class Program
{
public static int Even(int n)
{
int i, sumeven = 0;
for (i = 1; i <= n; i++)
{
if ((i % 2) == 0)
{
sumeven = sumeven + i;
}
}
return sumeven;

}
static void Main(string[] args)
{
int n,ans;
Console.WriteLine("ENTER THE LIMIT");
n = int.Parse(Console.ReadLine());
ans=Even(n);
Console.WriteLine("Sum of Even Numbers upto Given Limit is :" + ans);
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy