Week 2
Week 2
Problem Statement:
(A) Write a Program which determines the Conditional Statements Using If, If-
else, and Nested If –else Statements Weather the given Condition is
True/False Statements?
Aim:
Software Requirements:
Description:
Algorithm:
Step 1: Start.
Flow Chart:
1
Source Code:
#include <stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter an integer:\n");
scanf("%d", &n);
if (n%2 == 0)
printf("Even\n");
else
printf("Odd\n");
return 0;
}
Compiler (F9): Click on F9 to compile the program which helps us to find the
errors so that the file extends to Even and Odd.exe file name.
Run(F10): After compilation of the program click on F10 to run the program
and gives output.
Output 1:
Enter an integer:
2
Even
--------------------------------
Process exited after 2.009 seconds with return value 0
Press any key to continue . . .
Output 2:
Enter an integer:
3
Odd
2
--------------------------------
Process exited after 4.185 seconds with return value 0
Press any key to continue . . .
3
(B)Write a Program which determines the Conditional Statements Using If, If-
else, and Nested If –else Statements Weather the given Condition is
True/False Statements?
Aim:
Software Requirements:
Description:
A leap year is a year, which is different than a normal year having 366 days
instead of 365.
A leap year comes once in four years, in which February month has 29 days.
With this additional day in February, a year becomes a Leap year.
Some leap years examples are - 1600, 1988, 1992, 1996, and 2000.
Although 1700, 1800, and 1900 are century years, not leap years.
Below conditions are used to check that year is a leap year or not.
i) Year must be divisible by 4
ii) Year is divisible by 400 and not divisible by 100.
Algorithm:
Step 1: Start
Step 6: If the condition at step 3 and 5 becomes true, then the year is a leap
year.
Step 7: If the condition at step 4 becomes true, then the year is not a leap year.
4
Step 8: Stop.
Flow Chart:
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int year;
Compiler (F9): Click on F9 to compile the program which helps us to find the
errors so that the file extends to leap year.exe file name.
Run(F10): After compilation of the program click on F10 to run the program
and gives output
Output 1:
Enter a year
2000
2000 is a leap year
--------------------------------
Process exited after 3.458 seconds with return value 0
Press any key to continue . . .
Output 2:
5
Enter a year
2014
2014 is not a leap year
--------------------------------
Process exited after 3.181 seconds with return value 0
Press any key to continue . . .
Software Requirements:
Description:
1. 5! = 5*4*3*2*1 = 120
2. 3! = 3*2*1 = 6
Here, 5! is pronounced as "5 factorial", it is also called "5 bang" or "5 shriek".
Algorithm:
Step 1: Start
6
Step 7: Stop
Flow Chart:
Source Code:
#include <stdio.h>
#include<conio.h>
int main()
{
int i, n, fact = 1;
Compiler (F9): Click on F9 to compile the program which helps us to find the
errors so that the file extends to Fact.exe file name.
Run(F10): After compilation of the program click on F10 to run the program
and gives output
Output:
--------------------------------
Process exited after 3.55 seconds with return value 0
Press any key to continue . . .