-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
feaf1d8
commit c47eea1
Showing
8 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// DiscountCalculator.cpp : Program to calculate discount from bill amount | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
float billAmount, discount; | ||
cout << "Enter your bill amount: " << endl; | ||
cin >> billAmount; | ||
if (billAmount>=500.0) | ||
{ | ||
discount = 20; | ||
discount /= 100; | ||
billAmount = billAmount - billAmount * discount; | ||
cout << "Your discount is: " << discount * 100 << "%" << endl; | ||
cout << "Your bill after discount is: " << billAmount << endl; | ||
} | ||
else if (billAmount>=100 && billAmount<500) | ||
{ | ||
discount = 10; | ||
discount /= 100; | ||
billAmount = billAmount - billAmount * discount; | ||
cout << "Your discount is: " << discount * 100 << "%" << endl; | ||
cout << "Your bill after discount is: " << billAmount << endl; | ||
} | ||
else | ||
{ | ||
cout << "No discount for you :(" << endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// DisplayDigits.cpp : Program to print digits of a number in reverse | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int num, r; | ||
cout << "Enter the number: " << endl; | ||
cin >> num; | ||
while (num!=0) | ||
{ | ||
r = num % 10; | ||
num /= 10; | ||
cout << "Digit is: " << r << endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Factorial.cpp : Program to find factorial of a number | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int num, factorial; | ||
cout << "Enter number to find factorial of: " << endl; | ||
cin >> num; | ||
factorial = num; | ||
for (int i = num-1; i >= 1; i--) | ||
{ | ||
factorial *= i; | ||
} | ||
cout << "Factorial of " << num << " is: " << factorial << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// LeapYearChecker.cpp : Program to check if a year is leap year or not | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int year; | ||
cout << "Enter the year: " << endl; | ||
cin >> year; | ||
if (year%100==0) | ||
{ | ||
if (year/=100;year%4==0) | ||
{ | ||
cout << year*100 << " is a leap year" << endl; | ||
} | ||
else | ||
{ | ||
cout << year*100 << " is not a leap year" << endl; | ||
} | ||
} | ||
else | ||
{ | ||
if (year%4==0) | ||
{ | ||
cout << year << " is a leap year" << endl; | ||
} | ||
else | ||
{ | ||
cout << year << " is not a leap year" << endl; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// MultiplicationTable.cpp : Program to print multiplication table of a given number. | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int num, i, num1; | ||
cout << "Enter number to print table for: " << endl; // Using for loop | ||
cin >> num; | ||
for (int i = 1; i <= 10; i++) | ||
{ | ||
cout << num << " x " << i << " = " << num * i << endl; | ||
} | ||
i = 1; | ||
cout << "Enter number to print table for: " << endl; // Using while loop | ||
cin >> num1; | ||
while (i <= 10) | ||
{ | ||
cout << num1 << " x " << i << " = " << num1 * i << endl; | ||
i++; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// PerfectNumber.cpp : Program to check if a number is perfect or not | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int num, sum = 0; | ||
cout << "Enter number: " << endl; | ||
cin >> num; | ||
for (int i = 1; i <= num; i++) | ||
{ | ||
if (num%i==0) | ||
{ | ||
sum += i; | ||
} | ||
} | ||
sum -= num; | ||
if (sum==num) | ||
{ | ||
cout << num << " is a perfect number." << endl; | ||
} | ||
else | ||
{ | ||
cout << num << " is not a perfect number." << endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// PrimeNumber.cpp : Program to check if a number is prime or not | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int num, sum = 0; | ||
cout << "Enter number to check: " << endl; | ||
cin >> num; | ||
for (int i = 1; i <= num; i++) | ||
{ | ||
if (num%i==0) | ||
{ | ||
sum += i; | ||
} | ||
} | ||
if (num+1==sum) | ||
{ | ||
cout << num << " is a prime number." << endl; | ||
} | ||
else | ||
{ | ||
cout << num << " is not a prime number." << endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SumOfFirstnNaturalNumbers.cpp : Program to find sum of first n natural numbers using loops | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int n, m, sum = 0, sum1 = 0; | ||
cout << "Enter the value of n: " << endl; | ||
cin >> n; | ||
for (int i = 1; i <= n; i++) | ||
{ | ||
sum += i; | ||
} | ||
cout << "Sum of first " << n << " natural numbers is: " << sum << endl; | ||
cout << "Enter the value of m: " << endl; | ||
cin >> m; | ||
int j = 0; | ||
while (j<=m) | ||
{ | ||
sum1 += j; | ||
j++; | ||
} | ||
cout << "Sum of first " << m << " natural numbers is: " << sum1 << endl; | ||
return 0; | ||
} |