From c47eea1a7d3dd62e3d90d6c862bcc9931486f6db Mon Sep 17 00:00:00 2001 From: Furqan Abid Date: Fri, 16 Sep 2022 23:30:07 +0500 Subject: [PATCH] Today's Dump --- DiscountCalculator.cpp | 32 ++++++++++++++++++++++++++++++++ DisplayDigits.cpp | 17 +++++++++++++++++ Factorial.cpp | 18 ++++++++++++++++++ LeapYearChecker.cpp | 34 ++++++++++++++++++++++++++++++++++ MultiplicationTable.cpp | 24 ++++++++++++++++++++++++ PerfectNumber.cpp | 28 ++++++++++++++++++++++++++++ PrimeNumber.cpp | 27 +++++++++++++++++++++++++++ SumOfFirstnNaturalNumbers.cpp | 26 ++++++++++++++++++++++++++ 8 files changed, 206 insertions(+) create mode 100644 DiscountCalculator.cpp create mode 100644 DisplayDigits.cpp create mode 100644 Factorial.cpp create mode 100644 LeapYearChecker.cpp create mode 100644 MultiplicationTable.cpp create mode 100644 PerfectNumber.cpp create mode 100644 PrimeNumber.cpp create mode 100644 SumOfFirstnNaturalNumbers.cpp diff --git a/DiscountCalculator.cpp b/DiscountCalculator.cpp new file mode 100644 index 0000000..b8c9b14 --- /dev/null +++ b/DiscountCalculator.cpp @@ -0,0 +1,32 @@ +// DiscountCalculator.cpp : Program to calculate discount from bill amount + +#include +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; +} \ No newline at end of file diff --git a/DisplayDigits.cpp b/DisplayDigits.cpp new file mode 100644 index 0000000..193051e --- /dev/null +++ b/DisplayDigits.cpp @@ -0,0 +1,17 @@ +// DisplayDigits.cpp : Program to print digits of a number in reverse + +#include +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; + } +} \ No newline at end of file diff --git a/Factorial.cpp b/Factorial.cpp new file mode 100644 index 0000000..546971d --- /dev/null +++ b/Factorial.cpp @@ -0,0 +1,18 @@ +// Factorial.cpp : Program to find factorial of a number + +#include +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; +} \ No newline at end of file diff --git a/LeapYearChecker.cpp b/LeapYearChecker.cpp new file mode 100644 index 0000000..ca3bcf0 --- /dev/null +++ b/LeapYearChecker.cpp @@ -0,0 +1,34 @@ +// LeapYearChecker.cpp : Program to check if a year is leap year or not + +#include +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; +} \ No newline at end of file diff --git a/MultiplicationTable.cpp b/MultiplicationTable.cpp new file mode 100644 index 0000000..ba49e3e --- /dev/null +++ b/MultiplicationTable.cpp @@ -0,0 +1,24 @@ +// MultiplicationTable.cpp : Program to print multiplication table of a given number. + +#include +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; +} \ No newline at end of file diff --git a/PerfectNumber.cpp b/PerfectNumber.cpp new file mode 100644 index 0000000..4831dbc --- /dev/null +++ b/PerfectNumber.cpp @@ -0,0 +1,28 @@ +// PerfectNumber.cpp : Program to check if a number is perfect or not + +#include +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; +} \ No newline at end of file diff --git a/PrimeNumber.cpp b/PrimeNumber.cpp new file mode 100644 index 0000000..9cbfc2a --- /dev/null +++ b/PrimeNumber.cpp @@ -0,0 +1,27 @@ +// PrimeNumber.cpp : Program to check if a number is prime or not + +#include +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; +} \ No newline at end of file diff --git a/SumOfFirstnNaturalNumbers.cpp b/SumOfFirstnNaturalNumbers.cpp new file mode 100644 index 0000000..ca6380e --- /dev/null +++ b/SumOfFirstnNaturalNumbers.cpp @@ -0,0 +1,26 @@ +// SumOfFirstnNaturalNumbers.cpp : Program to find sum of first n natural numbers using loops + +#include +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; +} \ No newline at end of file