Nov 22, 2009

Math Program - arithmetical progression problem

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > C, C++ & Visual C++

Math Program - arithmetical progression problem

zitendr
Short program in c to calculate first term when sum of n terms and common difference d is given.

Comment/Reply (w/o sign-up)

seec77
I think you forgot to post the code! tongue.gif

Comment/Reply (w/o sign-up)

DrK3055A
QUOTE(seec77 @ Jul 11 2006, 11:19 AM) *

I think you forgot to post the code! tongue.gif


This program is inmediate. The sum of an arithmetic serie, when you know the first and last term of a serie of n elements:

S=N*(a[1]+a[N])/2;

but you know that

a[N]=a[1]+(N-1)*d;

Doing arithmetics, then:

a[1]=S/N-(N-1)*d/2;

a[n]=S/N+(N-1)*d/2;

CODE

#include <stdio.h>

int main()
{
    double d,s,a1,an;
    long n;
    printf("\nHow many terms? ");
    scanf("%d",&n);
    printf("\nSum of all terms? ");
    scanf("%lf",&s);
    printf("\nCommon difference? ");
    scanf("%lf",&d);

    a1=s/n-(n-1)*d/2;
    an=s/n+(n-1)*d/2;
    printf("\nFist term A[1]: %f\nLast term A[%d]: %f\n\nSerie:",a1,n,an);
    for(long i=1;i<=n;i++){
        printf("%f",a1+(i-1)*d);
        if(i<n) printf(", ");
        }
}

 

 

 


Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Math Program Arithmetical Progression

  1. C++ Meters To Feet And Feet To Meters Program - I made it (0)
  2. My First C++ Program: Area, Volume Etc. Calculator - My first program! (5)
    CODE //This program calculates the perimeter, area, surface area, or volume of any shape or
    solid. #include #include #define PI 3.14159265359 using namespace std; float psquare (float
    a) { return (4*a); } float prectangle (float w, float l) { return ((2*w)+(2*l)); } float
    pparallelogram (float b, float h) { return ((2*b)+(2*h)); } float ptrapezoid (float s, float t,
    float b) { return ((2*s)+b+t); } float pcircle (float r) { return (PI*r*2); } float pellipse
    (float r, float s) { return (PI*(r+s)); } float ptriangle (float a, float b, float c) { return (a+...
  3. Fibonacci Number Program Problem - n00b :) (5)
    I (finaly) started learning C. I'm using a book to learn it combined with some trial and error.
    Now I've made a program to calculate the Fibonacci numbers, but there seems to be some error.
    This is the source code: CODE #include   main() { int   fib1, fib2, fib, i, inp;
    printf("************************************************"); printf("\n* Welcome to the Fibonacci
    Number Program v0.1 *\n"); printf("************************************************");
    printf("\nWich Fibonacci Number do you want?\n"); scanf("%d", &inp); fib1 = 1; fib2 = 0; switch(inp)
     { ...
  4. Vc Runtime Lib Error When Run A Program - (3)
    the program was tested in my machine with VS.net installed. It run without any problem with 24
    hours. However, when I run it in other machine without VS.NET or VC ienvironment, it didn't
    works. Even I installed dot.net framework and copy MFC, VC's dll files to this PC, it just don;t
    run. The following are the dll files that I copied: mfc40.dll mfc40loc.dll mfc40u.dll mfc42.dll
    MFC42CHS.DLL mfc42loc.dll mfc42u.dll MFC71.dll MFC71CHS.DLL MFC71CHT.DLL mfc71d.dll MFC71DEU.DLL
    MFC71ENU.DLL MFC71ESP.DLL 2005-04-01 01:02 61,440 MFC71FRA.DLL 2005-04-01 01:02 61,440 MFC7...



Looking for math, program, arithmetical, progression, problem

See Also,

*SIMILAR VIDEOS*
Searching Video's for math, program, arithmetical, progression, problem
advertisement



Math Program - arithmetical progression problem

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com