Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Basic C++ Programs/Array.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
using namespace std;

int main()
{
int numbers[5], sum = 0;
cout << "Enter 5 numbers!"<<endl;
for (int i = 0; i < 5; ++i)
{
cout<<"Enter number "<<i+1<<" : ";
cin >> numbers[i];
sum += numbers[i];
}

cout << "Sum = " << sum << endl;

return 0;
}
36 changes: 36 additions & 0 deletions Basic C++ Programs/Calculator.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
using namespace std;

int main()
{
char o;
float num1, num2;

cout << "Enter an operator (+, -, *, /): ";
cin >> o;

cout << "Enter two operands: ";
cin >> num1 >> num2;

switch (o)
{
case '+':
cout << num1 << " + " << num2 << " = " << num1+num2;
break;
case '-':
cout << num1 << " - " << num2 << " = " << num1-num2;
break;
case '*':
cout << num1 << " * " << num2 << " = " << num1*num2;
break;
case '/':
cout << num1 << " / " << num2 << " = " << num1/num2;
break;
default:
// if operator doesn't match any case constant (+, -, *, /)
cout << "Error! operator is not correct";
break;
}

return 0;
}
26 changes: 26 additions & 0 deletions Basic C++ Programs/If-else.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
using namespace std;

int main()
{
int number;
cout << "Enter an integer: ";
cin >> number;

// checks if the number is positive
if ( number > 0)
{
cout << "You entered a positive integer: " << number << endl;
}
else if(number==0)
{
cout<<"You entered 0!"<<endl;
}
else{
cout<<"You entered a negetive integer: "<< number<<endl;
}

cout << "This statement is always executed.";
return 0;

}
24 changes: 24 additions & 0 deletions Basic C++ Programs/Largest element in an array.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
using namespace std;

int main()
{
int i, n;
float arr[100];
cout << "Enter total number of elements(1 to 100): ";
cin >> n;
cout << endl;
for(i = 0; i < n; ++i)
{
cout << "Enter Number " << i + 1 << " : ";
cin >> arr[i];
}
for(i = 1;i < n; ++i)
{

if(arr[0] < arr[i])
arr[0] = arr[i];
}
cout << "Largest element = " << arr[0];
return 0;
}
26 changes: 26 additions & 0 deletions Basic C++ Programs/Prime or Not.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
using namespace std;

int main()
{
int n, i;
bool isPrime = true;

cout << "Enter a positive integer: ";
cin >> n;

for(i = 2; i <= n / 2; ++i)
{
if(n % i == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
cout << "This is a prime number";
else
cout << "This is not a prime number";

return 0;
}