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; } OutputEnter 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 ExplainedYou 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 divisibility by 400. if it …

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 statementif else statementnested if else statementelse if Laddercondional operatorswitch/case constructBy using the above-given decision-making statement we can implement the sense in a program that program can create decision automatically.if-else statementSyntax-1if(condition) { statement1; statement2; statement3; ........ ........ } else { statement1; statement2; statement3; ........ ........ } Syntax-2if(condition) statement; else statement; Syntax ExplainedThe 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 case of more than one statement and if a…

Popular posts from this blog

Overview of Go lang

Arrays in C Language

String in golang

Data Types in Go language

Creating your first html page

Installing go lang

Say Hello world in Go lang

Arrays in Go lang

Decision Making in Go lang

Decision Making Statements