HELP

I am supposed to write a program to calculate to calculate the sum of these first 6 terms of this series 2-6+18-....

Comments

  • : I am supposed to write a program to calculate to calculate the sum of these first 6 terms of this series 2-6+18-....
    :
    Place the individual numbers in an array. Then loop (for-do) through those numbers while summing them.
  • i := 2;
    repeat
    i := i*(-3);
    until i >= max;

    just enter a number to max and there it will stop.

    dolev
  • [b][red]This message was edited by omair19 at 2005-8-3 8:59:34[/red][/b][hr]
    : I am supposed to write a program to calculate to calculate the sum of these first 6 terms of this series 2-6+18-....
    :
    well if you have the series of numbers and you know which one to add the program can be simple
    here is the code
    [code]
    var
    a,b,c,d,e,f,answer : integer
    begin
    a = 2
    b = -6
    c = 18
    d = 3
    e =5
    f = 4
    answer = a + b + c + d + e + f
    writeln (answer)
    readln
    end.
    [/code]
    pascal old timers, kindly rechek the code.


  • : [b][red]This message was edited by omair19 at 2005-8-3 8:59:34[/red][/b][hr]
    : : I am supposed to write a program to calculate to calculate the sum of these first 6 terms of this series 2-6+18-....
    : :
    : well if you have the series of numbers and you know which one to add the program can be simple
    : here is the code
    : [code]
    : var
    : a,b,c,d,e,f,answer : integer
    : begin
    : a = 2
    : b = -6
    : c = 18
    : d = 3
    : e =5
    : f = 4
    : answer = a + b + c + d + e + f
    : writeln (answer)
    : readln
    : end.
    : [/code]
    : pascal old timers, kindly rechek the code.

    Missing all of your line endings (;) and also, all of your equal signs should be ':=' because you are setting the values. Other than that, the syntax is okay.

    Phat Nat


  • : : [b][red]This message was edited by omair19 at 2005-8-3 8:59:34[/red][/b][hr]
    : : : I am supposed to write a program to calculate to calculate the sum of these first 6 terms of this series 2-6+18-....
    : : :
    : : well if you have the series of numbers and you know which one to add the program can be simple
    : : here is the code
    : : [code]
    : : var
    : : a,b,c,d,e,f,answer : integer
    : : begin
    : : a = 2
    : : b = -6
    : : c = 18
    : : d = 3
    : : e =5
    : : f = 4
    : : answer = a + b + c + d + e + f
    : : writeln (answer)
    : : readln
    : : end.
    : : [/code]
    : : pascal old timers, kindly rechek the code.
    :
    : Missing all of your line endings (;) and also, all of your equal signs should be ':=' because you are setting the values. Other than that, the syntax is okay.
    :
    : Phat Nat
    :
    :


    Or maybe you should investigate exactly what the properties of the series are, and try and see if there is some (more efficient)abstract way of computing the answer, instead of using a possible brute force approach. Or maybe I have got the cat by the tail?


  • [b][red]This message was edited by omair19 at 2005-8-4 11:24:25[/red][/b][hr]
    thanx phat net
    here is the correct code(i hope):-)
    [code]
    var
    a,b,c,d,e,f,answer : integer;
    begin
    a := 2;
    b := -6;
    c := 18;
    d := 3;
    e :=5;
    f := 4;
    answer := a + b + c + d + e + f;
    writeln (answer);
    readln;
    end.
    [/code]



  • : [b][red]This message was edited by omair19 at 2005-8-4 11:24:25[/red][/b][hr]
    : thanx phat net
    : here is the correct code(i hope):-)
    : [code]
    : var
    : a,b,c,d,e,f,answer : integer;
    : begin
    : a := 2;
    : b := -6;
    : c := 18;
    : d := 3;
    : e :=5;
    : f := 4;
    : answer := a + b + c + d + e + f;
    : writeln (answer);
    : readln;
    : end.
    : [/code]

    Looks right, but I agree with Anotns. The code that Dolev posted is much cleaner, shorter and more expandable. Say you need to do it for the first 185 numbers... well, have fun typing them all out. The code Dolev posted will handle any number of iterations.

    Also, looking again, the syntax is right, but how did you come up with the next three numbers (3,5 & 4)? I can't think of an equation that would use these. Anyways, practice makes ... better.

    Phat Nat

  • : : [b][red]This message was edited by omair19 at 2005-8-4 11:24:25[/red][/b][hr]
    : : thanx phat net
    : : here is the correct code(i hope):-)
    : : [code]
    : : var
    : : a,b,c,d,e,f,answer : integer;
    : : begin
    : : a := 2;
    : : b := -6;
    : : c := 18;
    : : d := 3;
    : : e :=5;
    : : f := 4;
    : : answer := a + b + c + d + e + f;
    : : writeln (answer);
    : : readln;
    : : end.
    : : [/code]
    :
    : Looks right, but I agree with Anotns. The code that Dolev posted is much cleaner, shorter and more expandable. Say you need to do it for the first 185 numbers... well, have fun typing them all out. The code Dolev posted will handle any number of iterations.
    :
    : Also, looking again, the syntax is right, but how did you come up with the next three numbers (3,5 & 4)? I can't think of an equation that would use these. Anyways, practice makes ... better.
    :
    : Phat Nat
    :
    :
    The last 3 numbers came from Antons post. He has just entered 3 additional numbers to fill the 6 without seeing (or taking into account) that it was a specific sequence of numbers.
  • : : Looks right, but I agree with Anotns. The code that Dolev posted is much cleaner, shorter and more expandable. Say you need to do it for the first 185 numbers... well, have fun typing them all out. The code Dolev posted will handle any number of iterations.
    : : Also, looking again, the syntax is right, but how did you come up with the next three numbers (3,5 & 4)? I can't think of an equation that would use these. Anyways, practice makes ... better.

    i avoided using loops and arrays because katlilip seems to be a beginner,you are right that it can be a problem declaring 185 variables
    but required(6) variables can declared and filled manually(with ease)evn if you dont use arrays for declaration and loops for assigning values
    and the three numbers 3,5 and 4 were used as example as katlilip only provided first three numbers and wanted a program to manupulatew first 6 numbers.




  • : i avoided using loops and arrays because katlilip seems to be a beginner,you are right that it can be a problem declaring 185 variables
    : but required(6) variables can declared and filled manually(with ease)evn if you dont use arrays for declaration and loops for assigning values
    : and the three numbers 3,5 and 4 were used as example as katlilip only provided first three numbers and wanted a program to manupulatew first 6 numbers.
    :


    you might be right about this but i learned that if you bring codes that are slight beyond your knowladge will made you to improve your knowladge to be able to figure that code. althought what i should do is only to answer about the question he asked in a way he can immediatly figure out, but maby showing new more efficient way can improve him a bit more.



  • : you might be right about this but i learned that if you bring codes that are slight beyond your knowladge will made you to improve your knowladge to be able to figure that code. althought what i should do is only to answer about the question he asked in a way he can immediatly figure out, but maby showing new more efficient way can improve him a bit more.
    :
    i agree with you!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories