[go: up one dir, main page]

0% found this document useful (0 votes)
4 views6 pages

Comprog Notes

Uploaded by

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

Comprog Notes

Uploaded by

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

COMPUTER PROGRAMMING

CC102: LECTURE 1

Computer Programming

●​ Software is a set of instructions that provides information to computers to solve problems. The
smallest form of software is a program.
●​ Computers understand instructions that are written in a specific syntax called a programming
language.
●​ Features fast, cheap, and 24/7 work, accurate data, storage capacity, and reliability.
●​ Programming languages are used to write instructions to computer systems.

Binary numbers allow computers to efficiently store and manipulate data, all by using a system of switches
that can be turned on or off (represented by the binary digits 0 and 1).
1 0

True/Present False/Absent

128 64 32 16 8 4 2 1

19 0 0 0 1 0 0 1 1

200 1 1 0 0 1 0 0 0

E10

●​ E10 (hexadecimal: 111000001000) usually refers to exponent 10 in decimal scientific notation.


●​ A way to express large (or small) numbers in shorthand.
●​ E10 means “×10^10.”
●​ 1.101E10 means 1.101 × 10^10 (in base 10)

➢​ There are 700 programming languages


➢​ First General Computer System: Electronic Numerical Integrator and Computer (ENIAC)

WHY LEARN PROGRAMMING?

●​ Programming is fun to work on.


●​ Pretty good salary
●​ Computer programs are used in every field
●​ Modern tools to increase productivity and performance

C PROGRAMMING

●​ It is an amazing and simple language that helps you develop complex software applications with ease.
●​ Invented by Dennis Ritchie (Father of C Programming) at Bell Laboratories in early 1970s
●​ Standard coding of C programming was done in 1968 by the American National Standards Institute as
ANSIC.
●​ C is a high-level programming language that supports low-level programming languages.
●​ The development of C language was followed by the origin of unix, the first operating system
implemented in a high-level language

WHY LEARN C?

-​ Versatile and most popular programming language in the world.


FEATURES OF C PROGRAMMING

★​ Library functions are predefined in C, making it an optimal choice for programming.


★​ Almost all programming languages derived from C inherited their features from C, the mother of all
programming languages.
★​ C is a compiler-based language. To execute a code, we first need to compile it
○​ you need to translate it into binary
○​ C compiler/Online Compiler
○​ Output is executable once compiled
★​ C is case sensitive; if you write “program” and “Program,” both of them would connote different meaning
in C

Weakness of C Programming

●​ Difficulties in making changes in the program that we write to solve the problems: modification and
update issues.
●​ Difficulties in debugging the errors During programming in C, correction of errors or bugs is
complex.
●​ Difficulties in writing complex code for solutions: it takes longer times and planning to write
programs for bigger projects.

CC102: LECTURE 2

Advantages of C language

●​ Structured Programming: C helps to organize code into modular and easy-to-understand structures.
With functions, loops, and conditionals, developers can produce clear code that is easy to maintain.
●​ Procedural Language: C follows a procedural paradigm that is often simpler and more straightforward
for some types of programming tasks.
●​ Versatility: C language is a versatile programming language and it can be used for various types of
software, such as system applications, compilers, firmware, application software, etc.
●​ Efficiency and speed: C is known for being high-performing and efficient.
●​ Portable: C programs can be compiled and executed on different platforms with minimal or no
modifications.
●​ Close to Hardware: C allows direct manipulation of hardware through the use of pointers and low-level
operations.
●​ Standard Libraries: C comes with a large standard library,, which helps developers write code more
efficiently by leveraging pre-built functions.

Drawbacks of C Language

●​ Manual Memory Management: C languages need manual memory management, where a developer
has to take care of allocating and deallocating memory explicitly.
●​ No Object-Oriented Feature: Nowadays, most of the programming languages support the OOPs
features. But the C language does not support it.
●​ No Garbage Collection: The C language does not support the concept of garbage collection. A
developer needs to allocate and deallocate memory manually, and this can be error-prone and lead to
memory leaks or inefficient memory usage.
●​ No Exception Handling: The C language does not provide any library for handling exceptions. A
developer needs to write code to handle all types of expectations.
Application of C language

1.​ System programming


2.​ Embedded Systems
3.​ Compilers and Interpreters
4.​ Database Systems
5.​ Networking Software
6.​ Game Development
7.​ Scientific and Mathematical App
8.​ Text editors and IDEs (Integrated Development Environment)

CC102: LECTURE 3

Syntax
#include <stdio.h>

int main() {
printf("Hello World!");
return 0;
}

Line 1: #include <stdio.h> is a header file library that lets us work with input and output functions, such as
printf() (used in line 4). Header files add functionality to C programs.

Line 2: A blank line. C ignores white space. But we


use it to make the code more readable.

Line 3: Another thing that always appear in a C program is main(). This is called a function. Any code inside
its curly brackets {} will be executed.

Line 4: printf() is a function used to output/print text to the screen. In our example, it will output "Hello
World!".

Line 5: return 0 ends the main() function.

Line 6: Do not forget to add the closing curly bracket } to actually end the main function.

Take note of the following:


●​ It is important that you end the statement with a semicolon ;
●​ printf: to print text or to output value
●​ \n: to make new line

Variables

Data types (Variables) Format Specifier

int (integers; whole numbers) “%d”

char (single character) “%c”

float (w/ decimal) “%f”

double “%lf”
string (multiple characters) “%s”

Example:
#include <stdio.h>

int main() {
int x = 15;
float deci = 15.99;
char letter = ‘D’;

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


printf("%f \n", deci);
printf("%c \n", letter);
return 0;
}

#include <stdio.h>

int main() {
char myText [] = “Hello”;
printf("%s", myText);

return 0;
}

Decimal Precision

Example:
#include <stdio.h>

int main() {
float myFloatNum = 3.5;
printf("%f", myFloatNum); //6 digits
printf("%.1f", myFloatNum); //1 digit
printf("%.2f", myFloatNum); //2 digits
printf("%.3f", myFloatNum); //3 digits
printf("%.4f", myFloatNum); //6 digits

return 0;
}

Arithmetic Operators

Operator Name Description Example

+ addition Add together two values x+y

- subtraction Subtracts one value from another x-y

* multiplication Multiplies two values x*y

/ division Divides one value by another x/y

% modulus Returns the division remainder x%y


++ increment Increase the value by 1 ++x

-- decrement Decrease the value by 1 -- x

Assignment Operators

Operator Example Same As

= x=5 x=5

+= x += 3 x=x+3

-= x -= 3 x=x-3

*= x *= 3 x=x*3

/= x /= 3 x=x/3

%= x %= 3 x=x%3

&= x &= 3 x=x&3

|= x|3 x=x|3

^= x^=3 x=x^3

>>= x >> = 3 x = x >> 3

<<= x << = 3 x = x << 3

Comparison operators

Operator Name Example Description

== Equal to x == y Returs 1 if the values are


equal

!= Not equal x != y Returns 1 if the values


are not equal

> Greater than x>y Returns 1 if the first


value is greater than the
second value

< Less than x<y Returns 1 if the first


value is less than the
second value

>= Greater than or equal to x >= y Returns 1 if the first


value is greater than, or
equal to, the second
value

<= Less than or equal to x <= y Returns 1 if the first


value is less than, or
equal to, the second
value
Logical Operators

Operator Name Example Description

&& AND x < 5 && x < 10 Returns 1 if both


statements are true

|| OR x < 5 || x < 4 Returns 1 if one of the


statements is true

! NOT !(x < 5 && x < 10) Reverse the result,


returns 0 if the result is 1

https://www.w3schools.com/c/index.php

You might also like