Berikut adalah source code untuk membuat Belah ketupat menggunakan C++, sesuai dengan inputan yang kita masukan :
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,d,e,f,g;
while(scanf("%d",&a)!=EOF)
{
b=100000;
d=0;
while(a>=1)
{
c=a;
c/=b;
d+=c;
a%=b;
b/=10;
}
if(d>=10)
{
a=d;
b=100;
d=0;
while(a>=1)
{
c=a;
c/=b;
d+=c;
a%=b;
b/=10;
}
if(d>=10)
{
a=d;
b=100;
d=0;
while(a>=1)
{
c=a;
c/=b;
d+=c;
a%=b;
b/=10;
}
}
}
for(e=-d;e<=d;e++)
{
for(g=((d+1)-(sqrt(e*e)));g<=d;g++)
{
printf(" ");
}
for(f=1;f<=((d+1)-(sqrt(e*e)));f++)
{
printf("*");
if(f!=((d+1)-(sqrt(e*e)))) printf(" ");
}
printf("\n");
}
}
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259&page=4
Kamis, 07 Juli 2011
Menghitung Jumlah Huruf Inputan dalam C++
Program ini berfungsi menentukan berapa jumlah kata yang kita inputkan
dalam hal ini spasi akan tetap di hitung sebagai nilai
contoh:
aku cinta = maka jumlah hurufnya yaitu 9 (termasuk spasi
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char nama[20];
gets(nama);
printf("panjang nama yang anda masukkan adalah %d",strlen(nama));
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259&page=2
dalam hal ini spasi akan tetap di hitung sebagai nilai
contoh:
aku cinta = maka jumlah hurufnya yaitu 9 (termasuk spasi
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char nama[20];
gets(nama);
printf("panjang nama yang anda masukkan adalah %d",strlen(nama));
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259&page=2
Menentukan Bilangan yang nilainya lebih kecil atau sama besar dengan strcmp
Program ini untuk menentukan Nilai mana yang lebih kecil ( input ke 1 atau inputan ke 2), atau jika sama-sama besar !
program ini menggunakan fungsi strcmp
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char nama1[20];
char nama2[20];
scanf("%s",nama1);
scanf("%s",nama2);
if(strcmp(nama1,nama2)<0)
{
printf("nama1 lebih kecil");
}
else if (strcmp(nama1,nama2)>0)
{
printf("nama2 lebih kecil");
}
else
{
printf("nama sama besar");
}
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259&page=2
program ini menggunakan fungsi strcmp
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char nama1[20];
char nama2[20];
scanf("%s",nama1);
scanf("%s",nama2);
if(strcmp(nama1,nama2)<0)
{
printf("nama1 lebih kecil");
}
else if (strcmp(nama1,nama2)>0)
{
printf("nama2 lebih kecil");
}
else
{
printf("nama sama besar");
}
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259&page=2
Random angka 1 - 8
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
int angka;
randomize();
angka=random(8)+1;
textcolor(angka);
cprintf("hasil random: %d ",angka);
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259&page=2
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
int angka;
randomize();
angka=random(8)+1;
textcolor(angka);
cprintf("hasil random: %d ",angka);
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259&page=2
Bola Pantul C++
#include<stdio.h>
#include<conio.h>
//#include<dos.h>
void delay(int i) {
int n,m,o;
for(n=0;n<i;n++){
for(m=0;m<i;m++){
for(o=0;o<i;o++) { } } }
}
void main() {
int x=15,y=4,ax=1,by=1;
clrscr();
_setcursortype(_NOCURSOR);
do {
gotoxy(x,y);
printf("hello");
delay(250);
gotoxy(x,y);
printf(" ");
if(x<2 || x>74) {
ax*=-1; //increament or decreament
}
if(y<2 || y>24) {
by*=-1; //increament or decreament
}
x+=ax;
y+=by;
}
while(!kbhit());
}
sumber : http://www.kaskus.us/showthread.php?t=1215259&page=2
#include<conio.h>
//#include<dos.h>
void delay(int i) {
int n,m,o;
for(n=0;n<i;n++){
for(m=0;m<i;m++){
for(o=0;o<i;o++) { } } }
}
void main() {
int x=15,y=4,ax=1,by=1;
clrscr();
_setcursortype(_NOCURSOR);
do {
gotoxy(x,y);
printf("hello");
delay(250);
gotoxy(x,y);
printf(" ");
if(x<2 || x>74) {
ax*=-1; //increament or decreament
}
if(y<2 || y>24) {
by*=-1; //increament or decreament
}
x+=ax;
y+=by;
}
while(!kbhit());
}
sumber : http://www.kaskus.us/showthread.php?t=1215259&page=2
Membalikan Kata dengan strrev C++
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
char a[10];
printf("Masukkan kata: ");
gets(a);
strrev(a);
printf("Jika dibalik menjadi : %s",a);
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
char a[10];
printf("Masukkan kata: ");
gets(a);
strrev(a);
printf("Jika dibalik menjadi : %s",a);
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259
Buble Sort User C++
#include<stdio.h>
#include<conio.h>
void main(){
int bil[5]={5,3,2,1,4};
int j,i,temp;
for(i=0;i<5;i++)
scanf("%d",&bil[i]);
for(j=0;j<4;j++)
{for(i=0;i<4-j;i++)
{if(bil[i]>bil[i+1])
{temp=bil[i];
bil[i]=bil[i+1];
bil[i+1]=temp;
}
}
}
for(i=0;i<5;i++)
printf("%d ",bil[i]);
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259
#include<conio.h>
void main(){
int bil[5]={5,3,2,1,4};
int j,i,temp;
for(i=0;i<5;i++)
scanf("%d",&bil[i]);
for(j=0;j<4;j++)
{for(i=0;i<4-j;i++)
{if(bil[i]>bil[i+1])
{temp=bil[i];
bil[i]=bil[i+1];
bil[i+1]=temp;
}
}
}
for(i=0;i<5;i++)
printf("%d ",bil[i]);
getch();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259
Langganan:
Postingan (Atom)