Posts

Showing posts with the label Conditional Statements in C

Decision Making Statement | Part-2

Check the year is leap year or not. #include<stdio.h> int main() { int year; printf("Enter any year: "); scanf("%d",&year); if(year % 100 == 0) { if (year % 400 == 0) { printf("%d is a leap year",year); } else { printf("%d is not a leap year",year); } }else { if(year % 4 == 0) { printf("%d is a leap year",year); } else { printf("%d is not a leap year",year); } } return 0; } Output Enter any year: 1996 1996 is leap year Enter any year: 2001 2001 is no a leap year Enter any year: 1800 1800 is not a leap year Program Explained You know the year which is divisible by 4 is called leap year, but what about the century? Each century is divisible by 4. but to check whether the century is a leap year or not we have to check its divisibility by 400. So the logic to check the year is a leap or not: First check the year is a century if the year is century then check its divisibili

Decision Making Statements

As in the real world we need to make decision according to the situation. In the same sense we need to make decision while creating program. For decision making C provides various construct as follows: if statement if else statement nested if else statement else if Ladder condional operator switch/case construct By using the above-given decision-making statement we can implement the sense in a program that program can create decision automatically. if-else statement Syntax-1 if(condition) { statement1; statement2; statement3; ........ ........ } else { statement1; statement2; statement3; ........ ........ } Syntax-2 if(condition) statement; else statement; Syntax Explained The block which is specified with if is called if-block and the block with else is called else block. If there is a single statement in if block or else block then no need to enclose in {} (curly braces). But in the ca

Popular posts from this blog

String in golang

Inline V/S Block Level Element

Arrays in C Language

Data Types in Go language

Printing in C programming

Variable Naming & Scope of Variable

Escape Sequence | Formatted Printing | Interview Questions

Floating point Data types in Go lang

Overview of Go lang

Literals in Java