100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Computer system £10.49
Add to cart

Lecture notes

Computer system

 0 view  0 purchase

Computer system, computer science, computer skills, computer language

Preview 3 out of 21  pages

  • July 24, 2023
  • 21
  • 2017/2018
  • Lecture notes
  • Prof
  • All classes
All documents for this subject (5)
avatar-seller
akhilagouri
if(b>a)

{

printf("b is greater");

}

}

Output

b is greater

#include <stdio.h>
int main()
{
int number;

printf("Enter an integer: ");
scanf("%d", &number);

// Test expression is true if number is less than 0
if (number < 0)
{
printf("You entered %d.\n", number);
}

printf("The if statement is easy.");

return 0;
}
Output 1
Enter an integer: -2
You entered -2.
The if statement is easy.

Output 2
Enter an integer: 5
The if statement in C programming is easy.

If-else statement : The if-else statement is an extension of the simple if statement. The
general form is. The if...else statement executes some code if the test expression is true (nonzero)
and some other code if the test expression is false (0).


C PROGRAMMING Page 60

, Syntax : if (condition)
{
true statement;
}
else
{
false statement;
}
statement-x;

If the condition is true , then the true statement and statement-x will be executed and if the
condition is false, then the false statement and statement-x is executed.
Or
If test expression is true, codes inside the body of if statement is executed and, codes inside the
body of else statement is skipped.
If test expression is false, codes inside the body of else statement is executed and, codes inside
the body of if statement is skipped.

Flowchart




Example:
// Program to check whether an integer entered by the user is odd or even

#include <stdio.h>
int main()
{

C PROGRAMMING Page 61

, int number;
printf("Enter an integer: ");
scanf("%d",&number);

// True if remainder is 0
if( number%2 == 0 )
printf("%d is an even integer.",number);
else
printf("%d is an odd integer.",number);
return 0;
}
Output
Enter an integer: 7
7 is an odd integer.


Nested if-else statement
When a series of decisions are involved, we may have to use more than on if-else statement in
nested form. If –else statements can also be nested inside another if block or else block or both.


Syntax : if(condition-1)
{ {
if (condition-2)
{
statement-1;
}
else
{
statement-2;
}
}
else
{
statement-3;


C PROGRAMMING Page 62

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller akhilagouri. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for £10.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

50843 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy revision notes and other study material for 14 years now

Start selling
£10.49
  • (0)
Add to cart
Added