Помогите, пожалуйста, с задачей с++

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by ASK.FM, 31 Oct 2013.

  1. ASK.FM

    ASK.FM New Member

    Joined:
    10 Aug 2012
    Messages:
    12
    Likes Received:
    1
    Reputations:
    0
    Добрый вечер, уважаемые античатовцы. Прошу у вас помоши с программой:
    [​IMG]

    // Лабораторная работа №5 _ 2 часть.cpp: определяет точку входа для консольного приложения.
    //

    #include "stdafx.h"


    int _tmain(int argc, _TCHAR* argv[])
    {
    return 0;
    }

    #include <iostream>
    #include <stdio.h>
    using namespace std;
    void main (void)
    { int x,y,a;
    int count;
    int factor;
    double s,sum;
    setlocale( LC_ALL,"Russian" );
    cout<<"Введите a";
    cin>>a;
    for (x = 1; x <= a; x=x*x)
    for(count=1;count<=a;count++)
    factor*=count;
    s=x/factor;
    sum=sum+s;
    cout<<sum;
    }
     
  2. muip

    muip New Member

    Joined:
    1 Sep 2011
    Messages:
    45
    Likes Received:
    4
    Reputations:
    0
    Code:
    
    #include "stdafx.h"
    #include <iostream>
    
    using namespace std;
    
    int factorial(int numeric)
    {
    	int fac = numeric;
    
    	for (int i = numeric - 1; i >= 2; i--)
    	{
    		fac *= i; 
    	}
    
    	return fac;
    }
    
    void main()
    {
    	int n;
    	double sum = 1;
    
    	cout << "Please, enter a value variable n: \n";
    	cin >> n;
    
    	for (int i = 2; i <= n; i++)
    	{
    		sum += (double)(i*i)/factorial(i);
    	}
    
    	cout << "Summa: " << sum;
    }
    
    
     
  3. ASK.FM

    ASK.FM New Member

    Joined:
    10 Aug 2012
    Messages:
    12
    Likes Received:
    1
    Reputations:
    0
    огромное вам спасибо)
     
  4. neviens

    neviens Member

    Joined:
    9 Oct 2013
    Messages:
    82
    Likes Received:
    28
    Reputations:
    3
    Чтобы зря процессор негонять, я бы добавил:
    Code:
    #include "stdafx.h"
    #include <iostream>
    #define _USE_MATH_DEFINES
    #include <math.h>
    //...
    void main()
    {
    //...
    	if(n > 16)
    		sum = M_E * 2;
    	else
    		for (int i = 2; i <= n; i++)
    		{
    			sum += (double)(i*i)/factorial(i);
    		}
    //...
    }