• Tidak ada hasil yang ditemukan

Fundamentals of Programming

N/A
N/A
Protected

Academic year: 2025

Membagikan "Fundamentals of Programming"

Copied!
32
0
0

Teks penuh

(1)

Fundamentals of Programming

Lecture 5

Introduction to C

(2)

Your first (?) C program

#include <stdio.h>

int main() {

puts("Salaaam! Chetoriiiii!!!???");

return 0;

}

prog1.c

(3)

Your first C program

#include <stdio.h>

int main() {

puts("Salaaam! Chetoriiiii!!!???");

return 0;

}

prog1.c

(4)

Your first C program

#include <stdio.h>

int main() {

printf("Salaaam! Chetoriiiii!!!???");

return 0;

}

prog2.c

(5)

Your first C program

#include <stdio.h>

int main() {

printf("Salaaam! Chetoriiiii!!!???");

return 0;

}

prog2.c

(6)

Your first C program

#include <stdio.h>

int main() {

printf("Salaaam! Chetoriiiii!!!???\n");

return 0;

}

prog3.c

(7)

Your first C program

#include <stdio.h>

int main() {

printf("Salaaam! Chetoriiiii!!!???\n");

return 0;

}

prog3.c

(8)

Your first C program

#include <stdio.h>

int main() {

printf("Salaaam! Chetoriiiii!!!???\n\n\n\n");

return 0;

}

prog4.c

(9)

Your first C program

#include <stdio.h>

int main() {

printf("Salaaam! Chetoriiiii!!!???\n\n\n\n");

return 0;

}

prog4.c

(10)

Your first C program

#include <stdio.h>

int main() {

printf("Salaaam! Chetoriiiii!!!???\n\n\n\n");

return 0;

}

prog4.c

(11)

Variables ﺎھرﯾﻐﺗﻣ

char c;

unsigned char uc;

signed char sc;

short sh;

unsigned short ush;

signed short ssh;

int i;

unsigned int ui;

signed int si;

long l;

unsigned long ul;

signed long sl;

variables.c

(12)

Variables ﺎھرﯾﻐﺗﻣ

short sh;

unsigned short ush;

signed short ssh;

int i;

unsigned int ui;

signed int si;

long l;

unsigned long ul;

signed long sl;

float f;

double d;

variables.c

(13)

Variables: the assignment operator (=)

#include <stdio.h>

int main() { int a;

a = -1;

printf("Salaaam! %d Chetor?\n", a);

return 0;

}

prog5.c

(14)

Variables: the assignment operator (=)

#include <stdio.h>

int main() { int a;

a = -1;

printf("Salaaam! %d Chetor?\n", a);

return 0;

}

prog5.c

(15)

Variables: the assignment operator (=)

#include <stdio.h>

int main() {

int a;

a = 10;

printf("%d\n",a);

return 0;

}

prog6.c

(16)

Variables: the assignment operator (=)

#include <stdio.h>

int main() {

int a;

a = 10;

printf("%d\n",a);

return 0;

}

prog6.c

(17)

the printf function formats

https://alvinalexander.com/programming/printf-format-cheat-sheet

(18)

reading variables

#include <stdio.h>

int main() {

int a;

scanf("%d", &a);

printf("%d\n",a);

return 0;

}

prog7.c

(19)

reading variables

#include <stdio.h>

int main() {

int a;

scanf("%d", &a);

printf("%d\n",a);

return 0;

}

prog7.c

(20)

reading variables

#include <stdio.h>

int main() {

int a;

scanf("%d", &a);

printf("%d\n",a*a);

return 0;

}

prog8.c

(21)

reading variables

#include <stdio.h>

int main() {

int a;

scanf("%d", &a);

printf("%d\n",a*a);

return 0;

}

prog8.c

(22)

reading variables

#include <stdio.h>

int main() {

int a,b;

scanf("%d", &a);

scanf("%d", &b);

printf("a=%d, b=%d, a+b=%d, a-b=%d\n", a, b, a+b, a-b);

return 0;

}

prog9.c

(23)

reading variables

#include <stdio.h>

int main() {

int a,b;

scanf("%d", &a);

scanf("%d", &b);

printf("a=%d, b=%d, a+b=%d, a-b=%d\n", a, b, a+b, a-b);

return 0;

}

prog9.c

(24)

reading variables

#include <stdio.h>

int main() {

int a,b;

scanf("%d %d", &a, &b);

printf("a=%d, b=%d, a+b=%d, a-b=%d\n", a, b, a+b, a-b);

return 0;

}

prog10.c

(25)

reading variables

#include <stdio.h>

int main() {

int a,b;

scanf("%d %d", &a, &b);

printf("a=%d, b=%d, a+b=%d, a-b=%d\n", a, b, a+b, a-b);

return 0;

}

prog10.c

(26)

Printing prompts

int main() { int a,b;

printf("Enter a: ");

scanf("%d", &a);

printf("Enter b: ");

scanf("%d", &b);

printf("%d + %d = %d\n", a, b, a+b);

return 0;

}

prompt.c

(27)

Printing prompts

int main() { int a,b;

printf("Enter a: ");

scanf("%d", &a);

printf("Enter b: ");

scanf("%d", &b);

printf("%d + %d = %d\n", a, b, a+b);

return 0;

}

prompt.c

(28)

Printing prompts

int main() { int a,b;

printf("Enter a: ");

scanf("%d", &a);

printf("Enter b: ");

scanf("%d", &b);

printf("%d + %d = %d\n", a, b, a+b);

return 0;

}

prompt.c

Be careful about autocorrection

systems (homework, exam). Do not

print prompts unless requested in

the question.

(29)

decision making یرﯾﮔ مﯾﻣﺻﺗ

#include <stdio.h>

int main() {

int a,b;

scanf("%d %d", &a, &b);

if (a > b) {

printf("a is bigger than b\n");

}

return 0;

}

prog11.c

(30)

decision making یرﯾﮔ مﯾﻣﺻﺗ

#include <stdio.h>

int main() {

int a,b;

scanf("%d %d", &a, &b);

if (a > b) {

printf("a is bigger than b\n");

}

return 0;

}

prog11.c

(31)

decision making یرﯾﮔ مﯾﻣﺻﺗ

#include <stdio.h>

int main() {

int a,b;

scanf("%d %d", &a, &b);

if (a > b) {

printf("a is bigger than b\n");

}

return 0;

}

prog11.c

(32)

decision making یرﯾﮔ مﯾﻣﺻﺗ

#include <stdio.h>

int main() { int a,b;

scanf("%d %d", &a, &b);

if (a > b) {

printf("a is bigger than b\n");

}

else {

printf("a is not bigger than b\n");

}

return 0;

}

prog12.c

Referensi

Dokumen terkait

Dendritic hairs with well-developed axis and moderate number of terete short to moder- ately long arms Figures 157-1 62: Tibouchina praecox LL, Monochaetum uenosum UL, Leandra

By adopting the ARDL model, this study analyses the short-run and long-run relationships between exchange rates and its macroeconomic fundamentals, namely inflation rate differential,

関数の返り値教科書では型,英語ではreturn valueとして使えるのは,これまでに出てきた, unsigned, signed char, int, float, double とこれから出てくる,ポインタ型, 構造体,共用体で, 配列を関数の返り値にはできません.. 配列を返り値にできない理由は,配列を代入によってコピーできないのと同じで,