Tuesday, November 10, 2015

Latihan 3



Soal 3
a.     
Kode Program:

#include<stdio.h>
#include<conio.h>
main()
{
        int i,j;
    for(i=5;i>-1;--i)
        {
                        printf("\n");
                        for(j=1;j<=i;++j)  
                        {
                                        printf("%3i", j);
                        }
            printf("  \n");
        }
        getch();
}
Hasil Program:


b.      
Kode program :

#include<stdio.h>
#include<conio.h>
main()
{      
        int i, j;
        for (i=1; i<=1; i++)
        {
                        printf("\n  ");
                        for (j=i; j<=5; j++)
                        {
                                        printf("%2i ", j);
                        }
                        printf("\n  ");
        }
        for (i=6; i<=6; i++)
        {
                        for (j=i; j<=9; j++)
                        {
                                        printf("%2i ", j);
                        }
                        printf("\n  ");
        }
        for (i=10; i<=10; i++)
        {
                        for (j=i; j<=12; j++)
                        {
                                        printf("%2i ", j);
                        }
                        printf("\n  ");
        }
        for (i=13; i<=13; i++)
        {
                        for (j=i; j<=14; j++)
                        {
                                        printf("%2i ", j);
                        }
                        printf("\n  ");
        }
        for (i=15; i<=15; i++)
        {
                        for (j=i; j<=15; j++)
                        {
                                        printf("%2i ", j);
                        }
                        printf("\n  ");
        }
        getch();
}

Hasil program :

c.        
Kode program :

#include<stdio.h>
#include<conio.h>
main()            
{
        int i, j;
        for(i = 5; i> 0; --i)
        {
            printf("\n");
                        for(j = 5 - i; j > 0; --j)
                        {
                                        printf(" ");
                        }
                        for(j = 1; j < i+1; ++j)
                        {
                                        printf("%d", j);
                        }
            printf("\n");
        }
        getch();
}

Hasil program :


d.       
Kode program :

#include<stdio.h>
#include<conio.h>
main()
{
        int i,j;
    for (i=1;i<=5;i++)
    {
                        for(j=1;j<=i;j++)
        {
            printf(" *");
        }
            printf("\n");
    }
        getch();
}

Hasil program :

e.       
Kode program :

#include<stdio.h>
#include<conio.h>
using namespace std;
main()
{
        int i, j, k, l;
        l=1;
        for (i=1;i<=5;i++)
    {
        for (j=4;j>=i;j--)
        {
            printf(" ");
        }
        for (k=0;k<l;k++)
        {
            printf("*");
                        }
                        printf("\n");
                        l=l+2;
        }
        getch();
}

Hasil program :


0 comments:

Post a Comment

 

Welcome To My Blog Template by Ipietoon Cute Blog Design