Algorithm and Data Structure "STRUCK"

  1. THEORY STUDY
    1.1.Pengertian
    Struct is a form data type that contains a collection of variables - variables that take shelter in one same name and have links to each other. Structs are just a collection of variables of the same data type, structs can have variables of the same or different data types, can even store variables of type data array or struct itself.
    Structs can be likened to an object. However, structs do not have an operation (method) or function. Structs can be used by creating a variable of type struct.
    The variables that are members of a struct are called struct elements. Structs also have a common form, namely:
    typedef struct {
    type_data <nama_var>;
    type_data <nama_var>;
    ....}
    1.2.How to use
  • Use / usage of struct data type is done by making a variable of type of data struct.
  • Accessing struct elements is done individually by naming the struct variable name followed by the point operator (.).
  1. DISCUSSION
    2.1.Implementation of the Program
    2.1.1. Program 1 (Biggest Function)
    · Program Listings
    #include
    int maximum (int, int);

int main (int argc, char * argv [])
{
int i = 4;
int j = 5;
int k;
k = maximum (i, j); / * calling function maximum or largest function * /
printf ("% d largest of% d and% d \ n", k, i, j);
printf ("% d largest of% d and% d \ n", maximum (3.5), 3, 5);
return 0;
}
int maximum (int a, int b)
/ * largest integer return * /
{
if (a> b)
return a;
return b;
}

2.1.2. Practice 2 (Student Data)
· Program Listings

#include
#include
#include

// Declaration of new data type of Student struct
typedef struct Student {
char NIM [9];
char name [30];
float ipk;
};

void main () {
// Create variable mhs of type Student data
Student mhs;
clrscr ();

  printf ("NIM ="); scanf ("% s", mhs.NIM);
  printf ("Name ="); scanf ("% s", mhs.name);
  printf ("IPK ="); scanf ("% f", & mhs.ipk);

  printf ("Your data: \ n");
  printf ("NIM:% s \ n", mhs.NIM);
  printf ("Name:% s \ n", mhs.name);
  printf ("GPA:% f \ n", mhs.ipk);
  getch ();

}
2.1.3. Practice 3 (Age)
· Program Listings

#include
#include
typedef int numbers;
typedef fractional float;
typedef char letters;
void main () {
clrscr ();
age number;
broken fragments;
letter h;

letter name [10];
printf ("Enter your age:");
scanf ("% d", & age);
printf ("your age is% d", age);
printf ("\ nnumber fractions:");
scanf ("% f", & broke);
printf ("fraction number f", broke);
printf ("enter letter:"); h = getche ();
printf ("\ nhuruf you% c", h);
printf ("\ nname in:");
scanf ("% s", name);
printf ("Your name% s", name);
getch ();
}
2.1.4. Practice 4 (Login ID)
· Program Listings
#include
#include
typedef struct Date {
int dd;
int mm;
int yyyy;
};

typedef struct Time {
int h;
int m;
int s;

                                };

typedef struct Login {
int ID;
Date tglLogin;
Time timeLogin;
};

int main () {
Login user1;

        printf ("USER 1 \ n");
        printf ("ID:"); scanf ("% d", & user1.ID);
        printf ("Date of Login \ n");
        printf ("Day:"); scanf ("% d", & user1.tglLogin.dd);
        printf ("Month:"); scanf ("% d", & user1.tglLogin.mm);
        printf ("Year:"); scanf ("% d", & user1.tglLogin.yyyy);
        printf ("Login Time \ n");
        printf ("Clock:"); scanf ("% d", & user1.waktuLogin.h);
        printf ("Minutes:"); scanf ("% d", & user1.waktuLogin.s);
        printf ("Seconds:"); scanf ("% d", & user1.waktuLogin.s);
        printf ("Thank you \ n");

        printf ("Your data: \ n");
                    printf ("ID:% d \ n", user1.ID);
                    printf ("Date:% d -% d -% d \ n", user1.tglLogin.dd, user1.tglLogin.mm, user1.tglLogin.yyyy);
                    printf ("ID:% d:% d:% d \ n", user1.waktuLogin.h, user1.waktuLogin.m, user1.waktuLogin.s)
                    getch ();

}
2.2.Results / Outputs
2.2.1. Practice 1 (Funtion Largest)
(i) This is the view of the program created using the largest function. This program is not an input program, so this program will directly display output in accordance with the coding program that we make. See (Figure 2.2.1.1 Display results from Maximum program)
56gwq5y83a.jpg

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center