Ada lagi nih... Source Code keren... Untuk menampilkan deret Bilangan prima.... Range-nya terserah...(Tergantung Inputan-nya mksud ane....)
silakan di coba...
#include <stdio.h>
#include <conio.h>
void main(){
int batas, i,x;
int bil_prima = 1;
printf("Masukkan batas : ");
scanf("%d", &batas);
printf(" 2");
for(i=3;i<=batas;i=i+2)
{
bil_prima = 1;
for(x = 3; i > x; x=x+2)
{
if(i % x == 0){
bil_prima = 0;
}
}
if(bil_prima==1)
printf(", %d ", i);
}
getch();
}
Sabtu, 07 Mei 2011
[C++] Perkalian 2 buah Matriks
Ada Tugas Suruh buat beginian...
langsung aja... Yg berminat Silakan Try....
#include "stdio.h"
#include "conio.h""
void main(){
int a[2][3],b[3][2],c[1][4],i,j,k,l,z=0,t=0,g,h;
for(i=0;i<2;i++){
for(j=0;j<3;j++){
printf("input data matrik A[%i][%i] : ",i+1,j+1);
fflush(stdin);scanf("%i", &a[i][j]);
}}
printf("\n");
for(i=0;i<3;i++){
for(j=0;j<2;j++){
printf("input data matrik B[%i][%i] : ",i+1,j+1);
fflush(stdin);scanf("%i", &b[i][j]);
}}
printf("\n print matrik A\n");
for(i=0;i<2;i++){
for(j=0;j<3;j++){
printf("%6i",a[i][j]);
}
printf("\n");
}
printf("\n print matrik B\n");
for(i=0;i<3;i++){
for(j=0;j<2;j++){
printf("%6i",b[i][j]);
}
printf("\n");
}
h=0; //nilai awal h, h=baris matrik a
for(k=0;k<2;k++){ //for untk perulangan baris matrik C
g=-1; //nilai awal g, g=kolom matrik b
for(l=0;l<2;l++){ //for::perulangan kolom matrik C
t=0; //mengembalikan/ set ulang nilai t=0
g=g+1; //berpindah kolom, g=kolom
for(j=0;j<3;j++) { //for::perulangan utk mngalikan matrik
z=a[h][j] * b[j][g]; //rumus: baris Matrik A X Kolom mtrik b
t=t+z; //mnjumlhkan nilai t + hasil dari rumus Z
c[k][l]=t; //memasukkan nilai total ke array sesuai index
} //kluar for perkalian
} //kluar for perulangan kolom
h=h+1; //pindah baris, h=baris
} //Keluar For
printf("\n Matrik C :\n");
for(k=0;k<2;k++){
for(l=0;l<2;l++){
printf("%6i",c[k][l]);
}
printf("\n");
}
getch();
}
langsung aja... Yg berminat Silakan Try....
#include "stdio.h"
#include "conio.h""
void main(){
int a[2][3],b[3][2],c[1][4],i,j,k,l,z=0,t=0,g,h;
for(i=0;i<2;i++){
for(j=0;j<3;j++){
printf("input data matrik A[%i][%i] : ",i+1,j+1);
fflush(stdin);scanf("%i", &a[i][j]);
}}
printf("\n");
for(i=0;i<3;i++){
for(j=0;j<2;j++){
printf("input data matrik B[%i][%i] : ",i+1,j+1);
fflush(stdin);scanf("%i", &b[i][j]);
}}
printf("\n print matrik A\n");
for(i=0;i<2;i++){
for(j=0;j<3;j++){
printf("%6i",a[i][j]);
}
printf("\n");
}
printf("\n print matrik B\n");
for(i=0;i<3;i++){
for(j=0;j<2;j++){
printf("%6i",b[i][j]);
}
printf("\n");
}
h=0; //nilai awal h, h=baris matrik a
for(k=0;k<2;k++){ //for untk perulangan baris matrik C
g=-1; //nilai awal g, g=kolom matrik b
for(l=0;l<2;l++){ //for::perulangan kolom matrik C
t=0; //mengembalikan/ set ulang nilai t=0
g=g+1; //berpindah kolom, g=kolom
for(j=0;j<3;j++) { //for::perulangan utk mngalikan matrik
z=a[h][j] * b[j][g]; //rumus: baris Matrik A X Kolom mtrik b
t=t+z; //mnjumlhkan nilai t + hasil dari rumus Z
c[k][l]=t; //memasukkan nilai total ke array sesuai index
} //kluar for perkalian
} //kluar for perulangan kolom
h=h+1; //pindah baris, h=baris
} //Keluar For
printf("\n Matrik C :\n");
for(k=0;k<2;k++){
for(l=0;l<2;l++){
printf("%6i",c[k][l]);
}
printf("\n");
}
getch();
}
Langganan:
Postingan (Atom)