1 / 11

Data Types

Data Types. Session 2. Data types in C. Primitive data types int , float, double, char Aggregate data types Arrays come under this category Arrays can contain collection of int or float or char or double data User defined data types Structures and enum fall under this category.

dunn
Télécharger la présentation

Data Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Types Session 2

  2. Data types in C • Primitive data types • int, float, double, char • Aggregate data types • Arrays come under this category • Arrays can contain collection of int or float or char or double data • User defined data types • Structures and enum fall under this category.

  3. How to Declare • Simple Data Type • int  integer  bil. bulat • float  floating point  bil. pecahan • char  character hanya 1 digit • char[pj] string  lebih dari 1 digit • How to declare • int jml_anak; • float nilai_mhs,rata2; • char sex,status; • char nm_mhs[20],almt[35];

  4. Variables • Variables are data that will keep on changing • Declaration <<Data type>> <<variable name>>; int a; • Definition <<varname>>=<<value>>; a=10; • Usage <<varname>> a=a+1; //increments the value of a by 1

  5. Variable names- Rules • Should not be a reserved word like int etc.. • Should start with a letter or an underscore(_) • Can contain letters, numbers or underscore. • No other special characters are allowed including space • Variable names are case sensitive • A and a are different.

  6. Variables • Variable Name for a memory object. Variable names must start with letters and contain letters, digits, and underscores. • a, b, i, j, counter, number_of_points, c1234, … • Type What the variable represents. Could be of integer, floating point number, character, string, and many others. • int, float, double, char, … • Declaration Tells compiler about variables and their type. • int i,j; • float sum;

  7. What’s string in turbo C • It’s NOT a string anymore. • It is seemed as a series of characters, which is a character array. • The number of the character array is just the same as the number of letters of the word or sentence plus one. • The one more element is “\0” which is printed as “\n” by gets and printed as “”(NULL) by other words.

  8. Numeric Types

  9. Reading Inputs • #include <stdio.h> • #include<conio.h> • void main() • { float bil1,bil2,hasil; //deklarasi variabel • clrscr(); //membersihkan layar • printf("Please input the first number : "); scanf("%f",&bil1); • printf("Please input the second number: "); scanf("%f",&bil2); • hasil = bil1 * bil2; //proses • printf(“bil1 * bil2 = %f\n“,hasil); //cetak hasil kali • getch(); //berhenti sebentar sampai ditekan tombol • } printf(“Hasil Kali dari %f dengan %f adalah %f “,bil1,bil2,hasil);

  10. Assignment • /* Arithmetic operators */ • #include <stdio.h> • #include<conio.h> • void main() • { • inta,c; • int b=4; • a=3; • c=a+b; • printf(“Sum: %d + %d -> %d\n”,a,b,c); • a++;b--; • prinf(“Now a=%d and b=%d\n”,a,b); • }

  11. Task 2 • Write a program to calculate the average of three floating point numbers. • Using scanffunction Buat program untuk meng-input-kan tiga buah bilangan pecahan sembarang kemudian hitung dan cetak rata-rata dari tiga bilangan tersebut.

More Related