Professional Documents
Culture Documents
Tugas Algoritma 50 Soal C++
Tugas Algoritma 50 Soal C++
Tugas Algoritma 50 Soal C++
#include<iostream.h>
#include<conio.h>
main()
{ int i,x;
for (i=8;i>=7;i--) // 1
{
cout<<i;
x=i;
while (x!=1)
{ cout<<i; x--; }
}
for ( i = 6 ; i>=5; i-- ) // 2
{
for ( x = i ; x>0; x-- )
{ cout<<x; }
}
for (i=4;i>=3;i--) // 3
{
cout<<i; x=i;
while (x!=1)
{ cout<<i; x--; }
}
for ( i = 2 ; i>=1; i-- ) // 4
{ for ( x = i ; x>0; x-- )
{ cout<<x; }
}
}
#include<iostream.h>
#include<conio.h>
main()
{
int i,x;
for ( i = 8 ; i>=7; i-- ) // 1
{
for ( x = i ; x>0; x-- )
{
cout<<x;
}
}
for (i=6;i>=5;i--) // 2
{
cout<<i;
x=i;
while (x!=1)
{ cout<<i; x--; }
}
for ( i = 4 ; i>=3; i-- ) // 3
{
for ( x = i ; x>0; x-- )
{ cout<<x; }
}
for (i=2;i>=1;i--) // 4
{
cout<<i;
x=i;
while (x!=1)
{ cout<<i; x--; }
}
}
for (n=r;n<=y;n++ )
{
if(n%10==2 && n%4==0)
{
cout<<endl<<n;
}
}
}
26. Menampilkan Tahun Kabisat Yg Angka Terakhirnya 4
#include <iostream.h>
int main()
{
int r=0,y=0,n;
cout<<"\nMasukkan Tahun Awal = ";
cin>>r;
cout<<"\nMasukkan Tahun Akhir = ";
cin>>y;
cout<<"\nTahun Kabisat antara Tahun "<<r
<<" sampai "<<y<<"\nYang Angka Terakhirnya ";
cout<<" sebagai berikut :"<<endl;
for (n=r;n<=y;n++ )
{
if(n%10==4 && n%4==0)
{
cout<<endl<<n;
}
}
}
for (z=0;z<1000;z++)
cout<<;
x++;
}
cin.get();
}
35. Animasi angka 0 berjalan dari pojok kiri atas hingga
pojok kanan atas dan kembali lagi dari
poJok kanan atas ke kiri atas dalam satu baris
#include <iostream>
#include <windows.h>
using namespace std;
void clrscr(void)
{ system(cls);
return; }
int main()
{
int x=0,y,z;
for(;;)
{
if (x==79)
{
for(x=79;x>0;)
{
clrscr();
for (y=0;y<x;y++)
cout<< ;
cout<<0;
for (z=0;z<1000;z++)
cout<< ;
x;
}
}
if (x==0)
{ for(x=0;x<79;)
{
clrscr();
for (y=0;y<x;y++)
cout<< ;
cout<<0;
for (z=0;z<1000;z++)
cout<< ;
x++;
}
}
}
cin.get();
}
cout<< ;
cout<<0;
for (z=0;z<1000;z++)
cout<<;
x;
}
}
if (x==0)
{
for(x=0;x<79;)
{
clrscr();
cout<<\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n\n\n\n\n;
for (y=0;y<x;y++)
cout<< ;
cout<<0;
for (z=0;z<1000;z++)
cout<<;
x++;
}
}
}
cin.get();
}
38. Animasi Angka 0 berjalan dari pojok kiri atas hingga
pojok kiri bawah dan kembali lagi dari pojok kiri atas
kepojok kiri bawah
#include<iostream.h>
#include<windows.h>
#include<conio.h>
void clrscr(void){
system("cls");
return;}
int main()
{ int x=0,y,z;
for(;;)
{ if (x==79)
{x=0;}
clrscr();
for (y=0;y<x;y++)
cout<<" "<<endl;
cout<<"0";
for (z=0;z<1000;z++)
cout<<"";
x++;
}
getch();
}
clrscr();
for (y=0;y<x;y++)
cout<<"\t\t\t\t\t\t\t\t\t
cout<<"\t\t\t\t\t\t\t\t\t
for (z=0;z<1000;z++)
cout<<"";
x++;
}
getch();
}
"<<endl;
0";
for(a=b+1, e=0;a<=c;a++)
{
for(d=a;d>1;d--)
{
if( !(a%d) && a!=d )//bukan bilangan prima
{
goto skip;
}
}
printf("%d, ",a);
skip:;
}
}