#include <iostream>
#include <stdio>
#include <conio>
#include <iomanip>
main()
{ //deklarasi variabel
int a=4;
char b='k';
char x[4]="bsi";
float c=7.35;
//macam-macam perintah
masukan dan keluaran
printf("belajar perintah
printf: ");
printf("%d \t\t\t %c
%10.1f \n",a,b,c); //format typedata hrs sesuai urutan dgn variabel
puts("belajar perintah
puts:");puts(x); //puts utk
string/kalimat
putchar('ini');putchar(b);cout<<endl; //putchar utk cetak 1 karakter
cout<<"contoh tipe
data integer:"<<a<<endl;
cout<<"menentukan
desimal:"<<setprecision(2)<<c;
getch();
}
Materi inputoutput
#include <iostream>
#include <stdio>
#include <conio>
main()
{
char
nm[25],kls[8],matkul[25];
int nilai;
//macam-macam perintah masukan
printf("Data nilai
siswa/i\n");
printf("=======================\n\n");
printf("input nama
siswa/i:");gets(nm);
printf("input kelas:
");gets(kls);
printf("input
matakuliah:");gets(matkul);
printf("input nilai
:");cin>>nilai;
clrscr();
printf("nama saya adalah
");printf("%s",nm);
printf(" dengan kelas
");printf("%s",kls);
printf("\nhari ini
belajar ");printf("%s",matkul);
printf("mudah-mudahan
nilainya
");printf("%d",nilai);
getch();
}
Beda getch dan getche
#include <conio>
#include <stdio>
main(){ char k;
printf("input:");k=getche();//atau
getch bedanya cuma ditampilkan & enter
printf("hasil
%c",k);
getch();
}
PERT1
Latihan
pert1
Latihan
pert1
Latihan Pert2
Output
#include <conio>
#include <iostream>
#include <stdio>
main(){
//algoritma dasar
int p,q,r,k,l,m;
p=0;q=5;r=10;
p=q;q=r;
cout<<p<<"
"<<q<<" "<<r;
//pertukaran
cout<<endl;
k=10;l=20;
m=k;k=l;l=m;
cout<<k<<l;
//strcat,strcmp
cout<<endl;
char a[15]="bsi";
char
b[15]="margonda";
strcat(a,b);
cout<<a;
cout<<strcmp(b,a);//selisih
hurufdepan, b ke m
cout<<endl;
//mencari posisi
char kar='r';
cout<<strchr(b,kar);
cout<<endl;
int i,j=0;
for(i=2;i<10;i+=2){
cout<<i;
if(i==4)continue;
if(i==8)break;
if(i<8)
cout<<"+";
j+=i;
}
cout<<"="<<j;
//fibonanci
cout<<endl;
int jumlah,s=1,t=1,o=1,n;
cout<<"jumlah
data:";cin>>jumlah;
for (n = 0; n < jumlah;
n++)
{
cout<<t<<"
";
o = s + t;
s = t;
t = o;
}
getch();
}