answersLogoWhite

0

Standard iterative solution:

int sumEvens = 0;
int sumOdds = 0;

int i;
for(i = 0; i <= n; ++i) {

if(i % 2 == 0) {
sumEvens += i;

}else {
sumOdds += i;

}

}


Clever way:

(This assumes all values are integer)

int num_odds = ((n - 1) >> 1) + 1; /* number of odd numbers from 1 to n */

int num_evens = n >> 1; /* number of even numbers from 1 to n */

int sum_odds = num_odds * num_odds;

int sum_evens = (num_evens * num_evens) + num_evens;

summing 10 numbers with variables

#include

main()

{

int a,b,c,d,e,f,g,h,i,j,add;

printf("Enter 10 numbers to sum:\t");

scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);

add = a+b+c+d+e+f+g+h+i+j;

printf("%dResult:\t",add);

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

Do Fibonacci Series program in dot net?

public static int fib(int n) {return fib(n-1) + fib(n-2);}


Write a program to print the series 072663124--term n?

To print the series 072663124 for a given term n, you can use a simple program in Python. The series appears to follow a specific pattern, so you can create a function that generates and prints the series up to the nth term. Here’s a basic implementation: def print_series(n): series = &quot;072663124&quot; print(series[:n]) # Example usage: n = 9 # specify the term you want to print print_series(n) This program prints the first n characters of the series. Adjust n to get the desired output.


Discontinuous function in fourier series?

yes a discontinuous function can be developed in a fourier series


Write a function to code the Fibonacci series in LISP programming language?

(defun fibo (n) (if (&lt; n 2) n (return (+ (fibo (- n 1)) (fibo (- n 2))))))


Write a program to print the Fibonacci series in php upto input value using recursive function?

The Fibonacci sequence uses recursion to derive answers. It is defined as: F0 = 0 F1 = 1 Fn = F(n - 1) + F(n -2) To have this sequence printed by a php script use the following: function fibonacci($n) { if($n 1) return 1; //F1 else return fibonacci($n - 1) + fibonacci($n - 2); //Fn } This recursive function will print out the Fibonacci number for the integer n. To make it print out all the numbers in a particular set add this to your script. for($i = 0; $i &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } So your final result would look like. &lt;?php function fibonacci($n) { if($n 1) return 1; else return fibonacci($n - 1) + fibonacci($n - 2); } for($i = 0; $i &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } ?&gt;

Related Questions

Write a javascript program for Fibonacci series?

I did this as an answre to some common js questions , the question wasWrite a function which will return you first two times 1, then 2, then 3, then 5 and so on (Fibonacci numbers). Don't use any global variables.var fibonacci = (function () {var arr = [0, 1];return function () {var num = arr[arr.length - 1],len = arr.length;arr.push(arr[len - 1] + arr[len - 2]);return num;};}());//testvar i;for (i = 0; i < 10; i++) {console.log(fibonacci());}//1,1,2,3,5,8,13,21,34,55


Can you have the program in C plus plus for recursive function generating a series of terms?

Yes, this can be done. For example for Fibonacci series. You will find plenty of examples if you google for the types of series you need to be generated.


What is the structure of logical argument?

An argument is a connected series of statements to establish a definite proposition. 3 stages to an argument: Premises, inference, and conclusion.


Is the word program a noun?

Yes, &quot;program&quot; can function as a noun. It can refer to a planned series of activities or events, a set of coded instructions input into a computer, or a specific performance or broadcast on television or radio.


Will Merlin return in 2012 for series 5?

Merlin will return for a 5th series in the autumn of 2012.


Do Fibonacci Series program in dot net?

public static int fib(int n) {return fib(n-1) + fib(n-2);}


What is the duration of Point of No Return TV series?

The duration of Point of No Return - TV series - is 2700.0 seconds.


Discontinuous function in fourier series?

yes a discontinuous function can be developed in a fourier series


When will Merlin return?

depends on which series though but i know that it will return for the 4th and 5th series on the 10th of auguest and in aututerm


When the regular series of MEDIUM will return when will the series MEDIUM return?

Sunday @ 9:00 EST in early 2009


What year will Green Lantern the Animated Series return?

It will never return. The series ended after one season in 2013.


When was Point of No Return - TV series - created?

Point of No Return - TV series - was created on 2003-11-03.