Pada kesempatan kali ini akan dibahas mengenai Array 2 Dimensi dan Structure pada Bahasa C. Array adalah sekelompok data yang disimpan berdasarkan index. Array 2 Dimensi merupakan array yang menyusun data array didalamnya, sehingga membentuk array di dalam elemen array utama. Stucture merupakan sebuah tipe data yang memiliki cakupan tipe data yang lain. Stucture hampir seperti tipe data yang telah kita buat sendiri. Pada video, akan dijelaskan mengenai deklarasi Structure dan implementasi Structure (input-output) serta deklarasi Array 2 Dimensi dan implementasinya.
Berikut ini saya akan membahas tentang Tugas VI soal no 2 yaitu menentukan tanggal untuk hari esok. Pada program ini meminta inputan dari user berupa tanggal hari ini. Kemudian disimpan pada sebuah struktur yang terdiri dari hari, bulan dan tahun. Kemudian menggunakan array 2 dimensi yang berisikan jumlah hari dalam satu bulan. Karena jumlah hari dalam satu bulan berbeda-beda, maka digunakanlah array untuk menentukannya. Berikut video tutorialnya :
This
is a source code about a program which can be used to insert student's
information. The user can insert ten students only. The information
about the students such as Number, nim, name, and value. After user
input information about the students already, the program will show ten
record of the students.
Source code:
#include <stdio.h> #include <stdlib.h>
int main(void) { int k; struct data { int number; char nim[20]; char name[20]; char value; }; struct data st[10]; printf("Input students' information\n"); for (k=0;k<10;k++) { printf("Input Data %d \n",k+1); printf("Number : "); fflush(stdin); scanf("%d", &st[k].number); fflush(stdin); printf("NIM : "); scanf("%s", &st[k].nim); fflush(stdin); printf("Name : "); scanf("%s", &st[k].name); fflush(stdin); printf("Value : "); scanf("%c", &st[k].value); }
Hello processor these code and video below are show you about how to create work date arithmetic program tomorrow :
#include <stdio.h>
#include <stdlib.h>
int main(){
struct days
{
int day;
int month;
int year;
};
struct days now,tomorrow;
int tdate[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
printf("Input value of day ");
scanf_s("%d",&now.day);
printf("\nInput value of month ");
scanf_s("%d",&now.month);
printf("\nInput value of year ");
scanf_s("%d",&now.year);
if(now.day<tdate[now.month-1])
{
tomorrow.day=now.day+1;
tomorrow.month=now.month;
tomorrow.year=now.year+1;
}
else if (now.month ==12)
{
tomorrow.day=1;
tomorrow.month=1;
tomorrow.year =now.year + 1;
}
else
{
tomorrow.day =1;
tomorrow.month = now.month + 1;
tomorrow.year = now.year;
}
printf("\n tomorrow is day %d month %d year %d \n", tomorrow.day,tomorrow.month,tomorrow.year);
system("pause");
}
int main(void) { struct date // We declare struct variable that have content date, month, year { int date; int month; int year; }; struct date now, tomorrow;
int tdate[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // element of array printf("Insert Today Date In This Format : dd mm yyyy\n"); scanf_s("%d %d %d", &now.date, &now.month, &now.year);