Skip to content

Commit

Permalink
Today's Dump
Browse files Browse the repository at this point in the history
  • Loading branch information
heyyfurqan authored Sep 16, 2022
1 parent feaf1d8 commit c47eea1
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 0 deletions.
32 changes: 32 additions & 0 deletions DiscountCalculator.cpp
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;
}
17 changes: 17 additions & 0 deletions DisplayDigits.cpp
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;
}
}
18 changes: 18 additions & 0 deletions Factorial.cpp
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;
}
34 changes: 34 additions & 0 deletions LeapYearChecker.cpp
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;
}
24 changes: 24 additions & 0 deletions MultiplicationTable.cpp
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;
}
28 changes: 28 additions & 0 deletions PerfectNumber.cpp
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;
}
27 changes: 27 additions & 0 deletions PrimeNumber.cpp
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;
}
26 changes: 26 additions & 0 deletions SumOfFirstnNaturalNumbers.cpp
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;
}

0 comments on commit c47eea1

Please sign in to comment.