inicio
double R = 1.0, T
int d
for (d = 2 to d=198 step d = d + 2)
{
T = 1.0 / d;
print"", T R = R + T }
print"La suma de la serie es ", R
} fin.
Utilice un programa para calcular la suma de los siguientes 100 términos de la serie:1+1.0/2.0+1.0/4.0+1.0/6.0+1.0/8.0+1.0/10.0+1.0/12.0.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
{
double R = 1.0, T;
int d;
for (d = 2; d <= 198; d = d + 2)
{
T = 1.0 / d; Console.Write("{0}\n", T);
R = R + T;
}
Console.Write("\n La suma de la serie es {0}", R);
Console.ReadLine(); } } } }
SUMA DE 100 TERMINOS (visual)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double x = 1.0, T;
int d;
for (d = 2; d <= 198; d = d + 2) { T = 1.0 / d; listBox1.Items.Add(""+ T.ToString()); x = x + T; } listBox1.Items.Add("\n La suma de la serie es " + x.ToString()); } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { Close(); } } }
No hay comentarios:
Publicar un comentario