Kampusti.info | Program C++ | Input/output dan Jenis Data 1
Program C++ dengan menggunakan fungsi puts 1
#include <stdio.h>
#include <conio.h>
main ()
{
puts("Hello World!");
getch();
}
Program C++ dengan menggunakan fungsi puts 2
#include <stdio.h>
#include <conio.h>
main ()
{
printf("Hai, nama saya Abgi");
printf("Saya sedang belajar memprogram memakai Bahasa C");
printf("Lumayan deh kalau sudah lancar nanti");
printf("OK, bye-bye ya.");
getch();
}
Program tampilan menggunkan kode escape
#include <stdio.h>
#include <conio.h>
main ()
{
printf("1 \t2 \t3 \t4 \t5 \t6 \t7 \t8 \n");
printf("Program \tKomputer\tBahasa\tC++");
printf("\tdi Lab\tini\n");
printf("Saya sedang mempelajari\r");
printf("kode escape\n");
printf("Suara apakah ini?\a");
getch();
}
Program Mengisi Input Ke Variabel string
#include <stdio.h>
#include <conio.h>
main()
{
char nama[80];
printf("Masukkan nama: ");
scanf("%s",nama);
printf("Halo ");
puts(nama);
printf("Betul kan, kamu si %s?\n", nama);
getch();
}
Program Matematika Bilangan Bulat dan Riil : Pembagian
#include <stdio.h>
#include <conio.h>
main()
{
int a = 10, c;
float b = 3.5, d;
c = a/b; d = a/b;
printf("a = %d\n",a);
printf("b = %f\n",b);
printf("c = %d\n",c);
printf("d = %f\n",d);
getch();
}
Program Input Ke Variabel Bilangan : Menghitung Akar
#include <stdio.h>
#include <math.h>
#include <conio.h>
main()
{
int a;
float b;
printf("Masukkan nilai a = ");
scanf("%d",&a);
b = sqrt (a);
printf("akar dari a = %f",b);
getch();
}
Program Menghitung Rata-Rata
#include <stdio.h>
#include <conio.h>
main()
{
int a, b, c, rerata;
printf("Masukkan nilai a, b dan c = ");
scanf("%d %d %d",&a,&b,&c);
rerata = (a+b+c)/3;
printf("Rerata = %d",rerata);
getch();
}
Program Menghitung Invers
#include <stdio.h>
#include <conio.h>
main()
{
int a;
float b, c;
printf("Masukkan a = ");
scanf("%d",&a);
b = 1/a;
printf("b = 1/%d = %f\n",a,b);
c = 1.0/a;
printf("c = 1/%d = %f\n",a,c);
getch();
}
Program Kepersisian Bilangan Riil
#include <stdio.h>
#include <conio.h>
main()
{
float a = 3, b;
double c;
b = 1000/a;
c = 1000/a;
printf("a = %f\n",a);
printf("b = %f\n",b);
printf("c = %f\n",c);
getch();
}
Program Pengaturan Tampilan
#include <stdio.h>
#include <conio.h>
main()
{
double a = 3.0, b;
b = 1000.0/a;
printf("a = %f\t\t b = %f\n",a,b);
printf("a = %7.2f\t\t b = %7.2f\n",a,b);
printf("a = %+7.4f\t\t b = %+7.4f\n",a,b);
printf("a = %g\t\t\t b = %g\n",a,b);
printf("a = %e\t b = %e\n",a,b);
printf("a = %5.2e\t b = %5.2e\n",a,b);
getch();
}
0 komentar
Post a Comment