answersLogoWhite

0


Best Answer

// Why do you need if/else statements?

int main()

{

int numbers[] = {1, 2, 3, 4, 5, 6}; // and so on

int i;

int sum = 0;

for(i = 0; i < sizeof (numbers)/sizeof(int); i++)

sum += i;

return sum;

}

User Avatar

Wiki User

βˆ™ 15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

βˆ™ 11y ago

#include main() /* program which introduces keyboard input */

{

inti = 1;

int inumber = 0;

int itotal = 0;

do

{

printf("Type in a number greater than zeroor zero to end program\n");

scanf("%d", &inumber);

printf("The number you typed was %d\n", inumber);

if (inumber 1);

printf("You ended the program, hit any key to continue\n");

getch();

}


This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program for Sum of n number using if else statements?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are sequential if then else patterns?

A sequential if-then-else pattern is a pattern where the program checks on thing at a time using if statements. For example, in C: if (condition 1) { do something 1; } else if (condition 2) { do something 2; } else if (condition 3) { do something 3; } else { do something else; } The first condition that is true will be executed.


What are the various control statement in C language?

Control statements are the statements that control the flow of program execution. For eg: loops: For, While, Do-While, decision making using if-then-else or switch-case and there's goto to transfer control.


Program for electricity bill using if-else ladder in c?

if (has_enough_money) { pay_the_bill(); }


Four basic instruction in C language?

They are 'statements' to speak strictly, they are: , , if, else, while, for, do, return, switch, break, continue, gotoNote: is zero or more statements between '{' and '}'


Structure of If-Then statement?

if (condition) statement1 [else statement2] example: if (i==j); else if (j==k) printf ("i!=j, j==k\n); else printf ("i!=j, j!=k\n); here statement1 is an empty-statement, statement2 is another if-statement There are three forms of statements IF-THEN IF-THEN-ELSE IF-THEN-ELSIF Sequence of statements is executed only if the condition evaluates to TRUE If condition evaluates to FALSE or NULL, it does nothing In either case control passes to next statement after the IF-THEN structure IF THEN statements; END IF; Sequence of statements in the ELSE clause is executed only if the condition evaluates to FALSE or NULL IF THEN statements; ELSE statements; END IF;

Related questions

Write a program By using if else statement to read a number and check whether it is positive or negative?

write a c++program by using if statement to read a number and check whether it is positive or negative


What are sequential if then else patterns?

A sequential if-then-else pattern is a pattern where the program checks on thing at a time using if statements. For example, in C: if (condition 1) { do something 1; } else if (condition 2) { do something 2; } else if (condition 3) { do something 3; } else { do something else; } The first condition that is true will be executed.


What are the various control statement in C language?

Control statements are the statements that control the flow of program execution. For eg: loops: For, While, Do-While, decision making using if-then-else or switch-case and there's goto to transfer control.


How do you group multiple PHP statements under an if statement?

If I got your question correctly, you want multiple statements to be executed using if-else statement. Here goes the code for it if($x&gt;0) { // multiple statments here // As long as statements are in curly bracket // All of them would execute // before the if statement finishes } else { // same way put all your multiple statements // in curly brackets. All of them would execute // using a single if-else statement }


Program for electricity bill using if-else ladder in c?

if (has_enough_money) { pay_the_bill(); }


Is it possible to use multiple else statements with if statements?

yes


You want to write program comparing 1 is greater than less than or equal to 100?

This requires a number of conditional statements, with IF. The details vary from one language to another; the result should be similar to this: x = 1 y = 100 if x &lt; y Output "The first number is greater" else if x &gt; y Output "The second number is greater" else Output "Both numbers are equal" end if Individual commands and statements must be adapted to the specific language, for example, the "Output" statement.


Four basic instruction in C language?

They are 'statements' to speak strictly, they are: , , if, else, while, for, do, return, switch, break, continue, gotoNote: is zero or more statements between '{' and '}'


Structure of If-Then statement?

if (condition) statement1 [else statement2] example: if (i==j); else if (j==k) printf ("i!=j, j==k\n); else printf ("i!=j, j!=k\n); here statement1 is an empty-statement, statement2 is another if-statement There are three forms of statements IF-THEN IF-THEN-ELSE IF-THEN-ELSIF Sequence of statements is executed only if the condition evaluates to TRUE If condition evaluates to FALSE or NULL, it does nothing In either case control passes to next statement after the IF-THEN structure IF THEN statements; END IF; Sequence of statements in the ELSE clause is executed only if the condition evaluates to FALSE or NULL IF THEN statements; ELSE statements; END IF;


What is the similarity between 'if' statement ans 'switch' statement?

A Switch statement can be considered as a series of if. else if. else statements. whatever condition is satisfied, the code block would get executed. if (cond 1) { } else if (cond 2) { } else if (cond 3) { } ...... } else if (cond N) { } else { } switch { case 1: .... case 2: .... .... case N: ... default: ... } Difference: In the if else blocks, if one condition is satisfied, all other blocks are ignored In Switch blocks, unless you have break statements inside each condition block, the subsequent blocks would not be ignored.


Java script program using if else?

Here we go... if(document.addListener){ alert("Yay! Not IE!"); }else{ alert("Booo! IE or something terribly old."); }


What is cyclomatic complexity?

Cyclomatic complexity is a software metric (measurement) developed by Thomas McCabe and is used to measure the complexity of a program. It directly measures the number of linearly independent paths through a program's source code. One of the ways is counting the number of closed loops in the flow graph, and incrementing the number by one. i.e. M = Number of closed loops + 1 where M = Cyclomatic number. Implications for Software Testing M is a lower bound for the number of possible paths through the control flow graph. M is an upper bound for the number of test cases that are necessary to achieve a complete branch coverage. For example, consider a program that consists of two sequential if-then-else statements. if (c1) { f1(); } else { f2(); } if (c2) { f3(); } else { f4(); } To achieve a complete branch coverage, two test cases are sufficient here. For a complete path coverage, four test cases are necessary. The cyclomatic number M is three, falling in the range between these two values, as it does for any program.