Jumat, 08 Februari 2013
1.program operator incremen dan decrement
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int x=10;
x = ++x;
cout<<"nilai x =%d\n"<<x;
x = ++x;
cout<<"nilai x =%d\n"<<x;
x = --x;
cout<<"nilai x = %d\n"<<x;
getch();
}
2program lain dengan menggunakan operator increment dan decrement
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int a,b,c;
a=5;
b=5;
c=a+b++;
cout<<"nilai c = %d\n"<<c;
getch();
}
3.perbedaan antara signed dan usigned
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
signed i=-127;
unsigned j;
j=i;
cout<<"i = %d<< j = %u\n"<<i,j;
getch();
}
4.program dengan float dan double
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
float x;
double y;
x=56.0123456789;
y=56.0123456789;
cout<<"x = %20.16f\n"<<x;
cout<<"y = %20.161F\n"<<y;
getch();
}
5.program dengan menggunakan variable
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int jumlah;
float harga_per_satuan, harga_total;
jumlah = 50;
harga_per_satuan = 15.7;
harga_total = jumlah*harga_per_satuan;
cout<<"harga total = %f\n"<<harga_total;
getch();
}
6.program menggunakan konstanta
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int a,b,c;
unsigned int d;
a =15;
b=017;
c=0xf;
d=55775U;
cout<<"a = %7d \n"<<a;
cout<<"b = %7d \n"<<b;
cout<<"c = %7d \n"<<c;
cout<<"d = %7d \n"<<d;
getch();
}
7.program menggunakan operator aritmatika
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
float luas,pi,jari,keliling;
pi = 3.1428;
jari = 12.0;
luas = pi*jari*jari;
cout<<"jari-jari = %f\n"<<jari;
cout<<"luas = %f "<<luas;
getch();
}
5
.//allasca: C++ tut 1
1.program operator incremen dan decrement Code: #include <iostream> #include <conio.h> using namespace std; int main() {...
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar