answersLogoWhite

0

// 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

16y ago

Still curious? Ask our experts.

Chat with our AI personalities

JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
RossRoss
Every question is just a happy little opportunity.
Chat with Ross
More answers

#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();

}


User Avatar

Wiki User

12y ago
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;