Program Memunculkan bilangan ganjil 1 sampai 10
Algoritma :
Deklarasi
i : integer
Deskripsi
for i <= 0 to 10 do
if (i mod 2 =1 )
then
write(i)
endif
endfor
#include<iostream.h>
#include<conio.h>
int main(){
int i;
for (int i=1; i<=10; i++)
{
if (i%2==1)
{
cout<<i<<" = ganjil"<<endl;
}
}
getch();
return 0;
}
Program class nya :
#include <cstdlib>
#include <iostream>
using namespace std;
class Ganjil {
public :
void keluaran();
private :
int i; // input
};
void Ganjil::keluaran() {
for (int i=1; i<=10; i++)
{
if (i%2==1)
{
cout<<i<<" = ganjil"<<endl;
}
}
}
int main(int argc, char *argv[])
{ Ganjil i;
i.keluaran();
system("PAUSE");
//return EXIT_SUCCESS;
}
Jeliot :
import jeliot.io.*;
class Ganjil {
public void keluaran(){
for (int i=1; i<=10; i++)
{
System.out.print("ganjil = " +i);
}
}
private int i; // input
public static void main() {
Ganjil i = new Ganjil();
i.keluaran();
}
}
In this case I would display the odd numbers from 1 to 10 by using the program C + + is a class in which the later will be imported into jeliot. Friends will be able to see the results of running this program using jeliot. Here I use a for loop and conditioning if.
Teman-teman silahkan mencoba program ini.... Semoga bermanfaat,, J
Program Bilangan habis di bagi 3 dan 5 dari 0 sampai 100
Algoritma :
Deklarasi
i : integer
Deskripsi
for i <= 0 to 100 do
if (i mod 3 = 0 and i mod 5 = 0 )
then
write(i)
endif
endfor
#include <iostream.h>
#include <conio.h>
int main() {
int i;
for (int i=1; i<=100; i++){
if (i%3==0 && i%5==0)
cout<<i<<endl;
}
getch();
return 0;
}
Program class :
#include <cstdlib>
#include <iostream>
using namespace std;
class bilangan {
public :
void keluaran();
private :
int i; // input
};
void bilangan::keluaran() {
for (int i=1; i<=100; i++)
{
if (i%3==0 && i%5==0)
{
cout<<i<<endl;
}
}
}
int main(int argc, char *argv[])
{ bilangan i;
i.keluaran();
system("PAUSE");
//return EXIT_SUCCESS;
}
Program jeliot nya :
import jeliot.io.*;
class bilangan {
public void keluaran(){
for (int i=1; i<=100; i++)
{
if(i%3==0 && i%5==0){
System.out.print(" " +i);
}
}
}
private int i; // input
public static void main() {
bilangan i = new bilangan();
i.keluaran();
}
}
In this program, namely the case where if we want to display the numbers 0 to 100 that runs out at the 3 and 5. Here I also use for loop to solve this case. And inside the loop using a conditioning if to perform a process in which his statement if (i mod 3 = 0 and i mod 5 = 0). Once the process runs its program.
Oya, teman-teman juga bisa melihatnya jeliotnya lhoo....
Thank you...
Mencari nilai minimum dan maksimum dan jumlah semua bilangan positif yang diinputkan.
Algoritma :
Deklarasi
nilai : integer
max,min,jumlah : integer
jumlah_inputan : float
Deskripsi
Jumlah inputan :
for <= i to jumlah_inputan do
then
write(nilai)
endfor
max = nilai
for <= i to jumlah_inputan do
if (nilai > max)
then
write(nilai)
endif
endfor
min = nilai
for <= i to jumlah_inputan do
if (nilai < min)
then
write(nilai)
endif
endfor
jumlah = nilai
for <= i to jumlah_inputan do
if ( nilai >=0 )
then
write(nilai)
endif
endfor
#include <iostream.h>
int main()
{
int nilai[25];
float jumlah_inputan;
int max, min, jumlah;
cout<< "masukkan jumlah inputan : ";
cin>> jumlah_inputan;
for(int i = 0; i < jumlah_inputan; i ++){
cout<< "masukkan nilai : ";
cin >> nilai[i];
cout<< endl;
}
max = nilai[0];
for(int i = 1; i < jumlah_inputan; i++){
if( nilai[i] > max){
max = nilai[i];
}
}
min = nilai[0];
for(int i = 1; i < jumlah_inputan; i++){
if( nilai[i] < min){
min = nilai[i];
}
}
jumlah = nilai[0];
for (int i = 1; i < jumlah_inputan; i++){
if ( nilai[i] >= 0 ){
jumlah = jumlah + nilai[i];
}
}
cout<< "nilai maksimum : "<< max <<endl;
cout<< "nilai minimum : "<< min <<endl;
cout<< "jumlah semua bilangan positif : "<<jumlah<<endl;
cout<< endl;
return 0;
}
In this case I asked to look for the largest number, smallest and the number of positive numbers are entered. To resolve this case I use for loop and use a conditioning if. In this program we are asked to input numbers we want directly from the keyboard. After that the program will continue in accordance with how many numbers you want entered. After that the program will select the number of the largest and the smallest number and add up all the positive numbers are entered. And the program will provide the appropriate output.
Thank you .... do not forget the try friends ..
Greetings IT ...
0 komentar:
Posting Komentar