Skip to content

Commit

Permalink
First Upload
Browse files Browse the repository at this point in the history
Some of my newbie tasks on cpp.
  • Loading branch information
debugvelop authored Oct 12, 2018
1 parent 3deedfb commit 7e2c6d7
Show file tree
Hide file tree
Showing 18 changed files with 575 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
using namespace std;

int main()
{
int x,y;
cout << "This is Array" << endl;
cout << "Masukan sebuah deret angka acak: ";
cin >> x;
int myArray[7];
for(y=0;y<x;y++)
{
int z=x%10;
int a=x/10;
x=a;
myArray[y]=z;
}
cout << myArray[1] << endl;
cout << myArray[3] << endl;
cout << myArray[5] << endl;

return 0;
}
28 changes: 28 additions & 0 deletions Array2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
cout << "Array Test Case" << endl;
char x[10];
char y[10];
cout << "Ketik sebuah kata: ";
cin >> x;

strcpy(y,"QWERT");
cout << "Tes strcpy : " << y << endl;

strncat(y,x,5);
cout << "Tes strncat: " << y << endl;

cout << "Tes strcmp : ";
cout << strcmp(x,y) << endl;

cout << "Jumlah array 1:";
cout << strlen(x) << endl;
cout << "Jumlah array 2:";
cout << strlen(y) << endl;

return 0;
}
19 changes: 19 additions & 0 deletions Array3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;

int main()
{
int transpose[3][3]={};
cout << "Masukan input matriks:" << endl;
cin >> transpose[0][0] >> transpose[0][1] >> transpose[0][2];
cin >> transpose[1][0] >> transpose[1][1] >> transpose[1][2];
cin >> transpose[2][0] >> transpose[2][1] >> transpose[2][2];

cout << "Hasil transpose:" << endl;
cout << transpose[0][0] << " " << transpose[1][0] << " " << transpose[2][0] << endl;
cout << transpose[0][1] << " " << transpose[1][1] << " " << transpose[2][1] << endl;
cout << transpose[0][2] << " " << transpose[1][2] << " " << transpose[2][2] << endl;

system("pause");
return 0;
}
22 changes: 22 additions & 0 deletions AskforInput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
using namespace std;

int main()
{
int x,y,z=1;
while(x!=0&&z<6)
{
cout << "Masukan angka=";
cin >> x;

y=x%2;
if(y!=0)
{
z=z+1;
}
}
cout << "Terimakasih \n";

return 0;

}
41 changes: 41 additions & 0 deletions Ato4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
using namespace std;

int main()
{
char x;
cout << "Masukan Skor Anda=";
cin >> x;

if(x=='A')
{
cout << "4" << endl;
}
else
{
if(x=='B')
{
cout << "3" << endl;
}
else
{
if(x=='C')
{
cout << "2" << endl;
}
else
{
if(x=='D')
{
cout << "1" << endl;
}
else
{
cout << "0" << endl;
}
}
}
}

return 0;
}
27 changes: 27 additions & 0 deletions Ato80.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
using namespace std;

int main()
{
int x;
cout << "Masukan nilai Anda=";
cin >> x;

if(x<50)
{
cout << "Nilai C";
}
else
{
if(x<=80)
{
cout << "Nilai B";
}
else
{
cout << "Nilai A";
}
}

return 0;
}
22 changes: 22 additions & 0 deletions AverageCalc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
using namespace std;

int main()
{
float a,b=0,c=0;
//This program will count the average of all the data, type "0" to show the average.
while(a!=0)
{
b=b+1;
cout << "Data " << b << "= ";
cin >> a;
c=c+a;
}

float average=c/(b-1);
cout << " \n";
cout << "Average= " << average << endl;

system("pause");
return 0;
}
42 changes: 42 additions & 0 deletions FPB.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
using namespace std;

int main()
{
int x,y,z,i,j;
cout << "Masukan angka pertama=";
cin >> x;
cout << "Masukan angka kedua=";
cin >> y;

if(x>y)
{
while(i!=0)
{
z=x;
y=z%y;
int i=x%y;
if(i==0)
{
cout << "FPB=" << y;
break;
}
}
}
else
{
while(i!=0)
{
z=y;
x=z%x;
int i=y%x;
if(i==0)
{
cout << "FPB=" << x;
break;
}
}

}
return 0;
}
52 changes: 52 additions & 0 deletions KPK.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>
using namespace std;

int main()
{
int x,y;
cout << "Masukan angka pertama" << endl;
cin >> x;
cout << "Masukan angka kedua" << endl;
cin >> y;

if(x>y)
{
int i=0;
while(i<=y)
{
i=i+1;
int z=x*i;
int j=z%y;
if(j==0)
{
cout << "KPK=" << z;
break;
}
else
{

}
}
}
else
{
int i=0;
while(i<=x)
{
i=i+1;
int z=y*i;
int j=z%x;
if(j==0)
{
cout << "KPK=" << z;
break;
}
else
{

}
}

}
return 0;
}
21 changes: 21 additions & 0 deletions LoadedDice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
using namespace std;

int main()
{
int x,y,z;
cout << "Masukan angka pada sisi dadu=";
cin >> x;
cout << "Angka di sisi samping dadu adalah ";

y=7-x;
for(z=1;z<7;z++)
{
if(z!=x&&z!=y)
{
cout << z << " ";
}
}

return 0;
}
25 changes: 25 additions & 0 deletions Loop counter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
using namespace std;

int main()
{
int n1,n2,a1=1,a2,a3=0;
cout << "Masukan nilai pertama=";
cin >> n1;
cout << "Masukan nilai kedua=";
cin >> n2;

if(n1>0&&n2>0)
{
while(a1<=n1)
{
for(a2=1;a2<=n2;a2++)
{
a3=a3+1;
cout << "Perulangan ke-" << a3 << endl;
}
a1++;
}
}
return 0;
}
30 changes: 30 additions & 0 deletions PrimeCheck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
using namespace std;

int main()
{
int x,y,z,a=0;
// This program will check if a number is a prime number
cout << "Number= ";
cin >> x;

for(y=2;y<=(x/2);y++)
{
z=x%y;
if(z==0)
{
a=a+1;
}
}
if(a==0)
{
cout << "A prime number" << endl;
}
else
{
cout << "Not a prime number" << endl;
}

system("pause");
return 0;
}
Loading

0 comments on commit 7e2c6d7

Please sign in to comment.