آموزش های کاربردی در دنیا رایانه و وب

به دست آوردن مجموع و میانگین

سوال : برنامه ای بنویسید که پنج عدد گرفته ، مجموع و میانگین را چاپ کند...(C#)



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

namespace Tamrin_2
{
    class Program
    {
        static void Main(string[] args)
        {
           
            int sum = 0;

  

        
            for (int Erfan = 0; Erfan < 5; Erfan++)
            {
                Console.WriteLine( "Please Sum These  Numbers : ");
                int a = Int32.Parse(Console.ReadLine());
                sum += a;
            }
            Console.WriteLine( "Sum is :" );
            Console.WriteLine(sum);
            {
                Console.WriteLine( "Please Calculate Average : " );
                int a = Int32.Parse(Console.ReadLine());
                int b = Int32.Parse(Console.ReadLine());
                int c = Int32.Parse(Console.ReadLine());
                int d = Int32.Parse(Console.ReadLine());
                int e = Int32.Parse(Console.ReadLine());
               
                sum =a + b + c + d + e ;
            }
            Console.WriteLine("Average is:"  );
            Console.WriteLine(sum / 5);
           
            Console.ReadKey();
        }

          }
}

  • Erfan_ 0098

نظرات  (۰)

هیچ نظری هنوز ثبت نشده است

ارسال نظر

ارسال نظر آزاد است، اما اگر قبلا در بیان ثبت نام کرده اید می توانید ابتدا وارد شوید.
شما میتوانید از این تگهای html استفاده کنید:
<b> یا <strong>، <em> یا <i>، <u>، <strike> یا <s>، <sup>، <sub>، <blockquote>، <code>، <pre>، <hr>، <br>، <p>، <a href="" title="">، <span style="">، <div align="">
تجدید کد امنیتی