-
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
Showing
7 changed files
with
281 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,17 @@ | ||
// Store integers using pointers | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int data[5]; | ||
cout << "Enter 5 integer values: "; | ||
for(int i = 0; i < 5; ++i) | ||
cin >> data[i]; | ||
|
||
cout << "You entered: "; | ||
for(int i = 0; i < 5; ++i) | ||
cout << endl << *(data + 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,63 @@ | ||
//Calculator menu | ||
# include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int menu; | ||
char choice; | ||
float num1, num2; | ||
bool run = true; | ||
|
||
while(run) | ||
{ | ||
cout << " MENU \n"; | ||
cout << " 1. Add \n 2. Subtract \n 3. Multiply \n 4. Divide \n 5. Modulus \n "; | ||
cout << "Enter your choice: "; | ||
cin >> menu; | ||
|
||
cout << "Enter your two numbers: \n"; | ||
cin >> num1 >> num2; | ||
|
||
int n1 = static_cast<int>(num1); | ||
int n2 = static_cast<int>(num2); | ||
|
||
switch(menu) | ||
{ | ||
case 1: | ||
cout << num1+num2; | ||
break; | ||
|
||
case 2: | ||
cout << num1-num2; | ||
break; | ||
|
||
case 3: | ||
cout << num1*num2; | ||
break; | ||
|
||
case 4: | ||
cout << num1/num2; | ||
break; | ||
|
||
case 5: | ||
cout << n1%n2; | ||
break; | ||
|
||
default: | ||
cout << "Error! operation is not correct"; | ||
break; | ||
} | ||
|
||
do{ | ||
cout<<"Would you like to perform other calculation?(Y/N)"<<endl; | ||
cin >> choice; | ||
choice = tolower(choice); | ||
}while (choice != 'n' && choice != 'y'); | ||
if(choice =='n'){ | ||
run = false; | ||
} | ||
|
||
} | ||
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,60 @@ | ||
//Max,min,mode | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int arr[10]; | ||
cout<<"Enter 10 integer values\n"; | ||
for(int i=0;i<10;i++) { | ||
cout<<"value "<<i<<":";cin>>arr[i]; | ||
} | ||
|
||
//find the max value | ||
int i,max; | ||
max = arr[0]; | ||
for(i=0;i<10;i++) | ||
if(max<arr[i]) { | ||
max=arr[i]; | ||
} | ||
|
||
cout<<"Max="<<max; | ||
cout<<"\n"; | ||
|
||
//find the min value | ||
int j,min; | ||
min = arr[0]; | ||
for(j=0;j<10;j++) | ||
if(min>arr[j]) { | ||
min=arr[j]; | ||
} | ||
|
||
cout<<"Min="<<min; | ||
cout<<"\n"; | ||
|
||
//find mode | ||
int number = arr[0]; | ||
int mode = number; | ||
int count = 1; | ||
int countMode = 1; | ||
|
||
for (int i=1; i<10; i++) | ||
{ | ||
if (arr[i] == number) | ||
{ | ||
++count; | ||
} | ||
else | ||
{ | ||
if (count > countMode) | ||
{ | ||
countMode = count; | ||
mode = number; | ||
} | ||
count = 1; | ||
number = arr[i]; | ||
} | ||
} | ||
cout << "mode : " << mode << 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,31 @@ | ||
//Sort | ||
#include <iostream> | ||
using namespace std; | ||
|
||
void BubbleSort(inst temp[], int len); | ||
|
||
int main() | ||
{ | ||
int arr[10]; | ||
cout<<"Enter 10 integer values\n"; | ||
for(int i=0;i<10;i++) { | ||
cout<<"value "<<i<<":";cin>>arr[i]; | ||
} | ||
|
||
BubbleSort(arr,10); | ||
} | ||
|
||
void BubbleSort(int temp[], int len) | ||
{ | ||
for( int i = 9 ; i > 0 ; i--){ | ||
for( int j = 0 ; j < i ; j++ ){ | ||
if(temp[j]>temp[j+1]) | ||
{ | ||
swap(temp[j],temp[j+1]); | ||
} | ||
} | ||
} | ||
for(int i=0 ; i< len ; i++){ | ||
cout<<temp[i]<<" "; | ||
} | ||
} |
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,44 @@ | ||
//Pascal Triangle | ||
#include<iostream> | ||
#include<conio.h> | ||
using namespace std; | ||
|
||
void Pascal(int size); | ||
int main() | ||
{ | ||
int size; | ||
cout<<"Enter Pascal triangle size:"; | ||
cin>>size; | ||
Pascal(size); | ||
getch(); | ||
return 0; | ||
} | ||
|
||
|
||
|
||
void Pascal(int size){ | ||
int PascalTr[size][size]; | ||
int row,col; | ||
//assign zero to every array element | ||
for(row=0;row<size;row++) | ||
for(col=0;col<size;col++) PascalTr[row][col]=0; | ||
//first and second rows are set to 1s | ||
PascalTr[0][0]=1; | ||
PascalTr[1][0]=1; | ||
PascalTr[1][1]=1; | ||
|
||
for(row=2;row<size;row++){ | ||
PascalTr[row][0]=1; | ||
for(col=1;col<=row;col++){ | ||
PascalTr[row][col]=PascalTr[row-1][col-1]+PascalTr[row-1][col]; | ||
} | ||
} | ||
//display the Pascal Triangle | ||
for(row=0;row<size;row++){ | ||
for(col=0;col<=row;col++){ | ||
printf("%d\t",PascalTr[row][col]); | ||
} | ||
cout<<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,29 @@ | ||
//find max using pointers | ||
#include<iostream> | ||
#include<conio.h> | ||
using namespace std; | ||
|
||
int *findMax(int arr[],int n); | ||
int main(){ | ||
int n,i,*p; | ||
cout<<"Enter number of data values: "; | ||
cin>>n; | ||
int arr[n]; | ||
for(i=0;i<n;i++) { | ||
cout<<"Enter value"<<i+1<<":"; | ||
cin>>arr[i]; | ||
} | ||
p=findMax(arr,n); | ||
cout<<"The max value is:"<<*p; | ||
getch(); | ||
return 0; | ||
} | ||
|
||
int *findMax(int data[],int n){ | ||
int *max=data; | ||
int i; | ||
for(i=1;i<n;i++){ | ||
if(*max<*(max+i)) *max=*(max+i); | ||
} | ||
return max; | ||
} |
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,37 @@ | ||
// Sort integers using pointers | ||
#include<iostream> | ||
#include<conio.h> | ||
|
||
using namespace std; | ||
int *sortAsc(int *p, int size); | ||
int main() | ||
{ | ||
int arr[10]; | ||
cout << "Enter 10 integer values: "; | ||
for(int i = 0; i < 10; ++i) | ||
cin >> arr[i]; | ||
|
||
int *p=sortAsc(arr,10); | ||
//output the sorted array | ||
int i; | ||
for(i=0;i<10;i++) | ||
cout<<*(p+i)<<endl; | ||
|
||
getch(); | ||
return 0; | ||
|
||
} | ||
|
||
|
||
int *sortAsc(int *p, int n){ | ||
int i,j; | ||
for(i=0;i<n;i++) | ||
for(j=i+1;j<n;j++) | ||
if(*(p+j)<*(p+i)) | ||
{ | ||
int temp=*(p+j); | ||
*(p+j)=*(p+i); | ||
*(p+i)=temp; | ||
} | ||
return p; | ||
} |