0% found this document useful (0 votes)
74 views

Tugas No. 1: Pengurutan Angka

The document contains 4 C programming assignments completed by Devina Aulia Azzahra. The first program sorts numbers in descending order. The second program multiplies two matrices. The third program generates a Pascal's triangle. The fourth program searches for a number input by the user in an array.

Uploaded by

Lia Namikaze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Tugas No. 1: Pengurutan Angka

The document contains 4 C programming assignments completed by Devina Aulia Azzahra. The first program sorts numbers in descending order. The second program multiplies two matrices. The third program generates a Pascal's triangle. The fourth program searches for a number input by the user in an array.

Uploaded by

Lia Namikaze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Tugas No.

1 : Pengurutan Angka
#include <stdio.h>
int main()
{
printf("Nama\t: Devina Aulia Azzahra\n");
printf("NIM\t: 205060300111041\n\n\n");

int number[30];
int i, j, a, n;

printf("Enter the value of N\n");


scanf("%d", &n);
printf("Enter the numbers \n");

for (i = 0; i < n; i++)


{
scanf("%d", &number[i]);
}
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (number[i] < number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
printf("The numbers arranged in descending order are given below\n");
for (i = 0; i < n; i++)
{
printf("%d\n", number[i]);
}
return 0;
}
Tugas No. 2 : Perkalian Matriks
#include <stdio.h>
//program perkalian matrix
int main()
{
printf("Nama\t: Devina Aulia Azzahra\n");
printf("NIM\t: 205060300111041\n\n\n");

int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];

printf("Enter the number of rows and columns of first matrix\n");


scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");

for (c = 0; c < m; c++)


for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);

printf("Enter the number of rows and columns of second matrix\n");


scanf("%d%d", &p, &q);

if (n != p)
printf("Matrices with entered orders can't be multiplied with each other.\n");
else
{
printf("Enter the elements of second matrix\n");

for (c = 0; c < p; c++)


for (d = 0; d < q; d++)
scanf("%d", &second[c][d]);
for (c = 0; c < m; c++)
{
for (d = 0; d < q; d++)
{
for (k = 0; k < p; k++)
{
sum = sum + first[c][k] * second[k][d];
}

multiply[c][d] = sum;
sum = 0;
}
}

printf("Product of entered matrices:-\n");

for (c = 0; c < m; c++)


{
for (d = 0; d < q; d++)
printf("%d\t", multiply[c][d]);

printf("\n");
}
}
return 0;
}
Tugas No. 3 : Segitiga pascal
#include <stdio.h>
//program pembuat segitiga pascal
long fact(int);

int main()
{
printf("Nama\t: Devina Aulia Azzahra\n");
printf("NIM\t: 205060300111041\n\n\n");
int line, i, j;

printf("Enter the no. of lines: ");


scanf("%d", &line);

for (i = 0; i < line; i++)


{
for (j = 0; j < line - i - 1; j++)
{
printf(" ");
}

for (j = 0; j <= i; j++)


{
printf("%ld ", fact(i) / (fact(j) * fact(i - j)));
}

printf("\n");

}
return 0;
}
long fact(int num)
{
long f = 1;
int i = 1;

while (i <= num)


{
f = f * i;
i++;
}
return f;
}
Tugas No. 4 : Pencarian data
#include<stdio.h>
//program pencari nilai yang diinput
int main()
{
int a[30], ele, num, i;

printf("\nEnter no of elements :");


scanf("%d", &num);

printf("\nEnter the values :");


for (i = 0; i < num; i++)
{
scanf("%d", &a[i]);
}
printf("\nEnter the elements to be searched :");
scanf("%d", &ele);
i = 0;
while (i < num && ele != a[i])
{
i++;
}
if (i < num)
{
printf("Number found at the location = %d", i + 1);
}
else
{
printf("Number not found");
}
return (0);
}

You might also like