1.menentukan kpk
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int a,b,kpk;
cout<<"mmenghitung kpk"<<endl;
cout<<"masukan bilangan pertama:";cin>>a;
cout<<"masukan bilangan kedua:";cin>>b;
kpk=0;
for(int i=1;i<=b;i++)
{
kpk=kpk+a;
if(kpk%b==0)
{
cout<<"kpk antara"<<a<<"dan"<<b<<"adalah"<<kpk<<endl;
break;
}
}
return 0;
}
2. menentukan fbp
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int a,b,fbp;
cout<<"masukan bilangan pertama:";cin>>a;
cout<<"masukan bilangan kedua:";cin>>b;
cout<<"nilai fbp dari"<<a<<"dan"<<b<<"adalah";
fbp=a%b;
while(fbp!=0)
{
a=b;
b=fbp;
fbp=a%b;
}
cout<<b<<endl;
return 0;
}
3. membuat program tipe karakter
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int a;
char karakter='A';
char*teks=(char*)"kata";
char TEKS[10]="coba";
cout<<karakter<<endl;
cout<<teks<<endl;
cout<<TEKS<<endl;
return 0;
}
Tidak ada komentar:
Posting Komentar