C Programming Fundamentals: Introduction to Variables, Data Types, and Input/Output, Slides of Programming for Engineers

this is slide for Programming Fundamentals for Engineers in c languge

Typology: Slides

2021/2022

Uploaded on 05/18/2023

khader-qaabar-1
khader-qaabar-1 šŸ‡µšŸ‡ø

5 documents

1 / 53

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Programming Fundamentals for Engineers
0702113
1. Introduction and C
Fundamentals
Muntaser Abulafi
Dr. Labib Arafeh
Yacoub Sabatin
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35

Partial preview of the text

Download C Programming Fundamentals: Introduction to Variables, Data Types, and Input/Output and more Slides Programming for Engineers in PDF only on Docsity!

Programming Fundamentals for Engineers

1. Introduction and C

Fundamentals

Muntaser Abulafi

Dr. Labib Arafeh

Yacoub Sabatin

  1. Pseudo-code:
    1. An outline of a program or algorithm, written in a form that can easily be converted into real programming statements;
    2. E.g. the pseudo-code for a bubble sort routine might be written: while not at end of list compare adjacent elements if second is greater than first switch them get next two elements if elements were switched repeat for entire list
  1. Code the program -- write the program;
  2. Test the program --run it;
  3. Debug the program (fix errors if any);
  4. Document completed program (final pseudo-code, flowchart, print chart, etc.). 2. Flow Charts:
  5. A flow chart is defined as a pictorial representation describing a procedure;
  6. Provides people (Developers, programmers , etc.) with a common language or symbolic reference point; 4 (Use: MS Visio)

5

3. An algorithm is a formula or set of steps for solving a particular problem;

  1. A clear set of rules; and
  2. Have a clear stopping point.
  3. Algorithms can be expressed in any language, from natural languages like English or French or Hindi to programming languages like QBASIC, C, etc. 4. Example : Add Two numbers, display both numbers and the sum: **1. START
  4. Input number1, number
  5. Sum = number1 + number
  6. Display heading message ā€œNumber1, Number2, Sumā€
  7. Display number1, number2, Sum
  8. End**

5. Pseudo-code: An outline of a program or algorithm, written in a form that can easily be converted into real programming statements; 1. Example : The pseudo-code to add two numbers might be written: Start Input number1, number Sum = number1 + number Display heading message ā€œNumber1, Number2, Sumā€ Display number1, number2, Sum End 2. Can not be compiled nor executed, and there are no real formatting or syntax rules. 6. Caution: Never write your program before either Algorithming, flowcharting or pseudo-coding it. 7

Develop a C program to Compute the Volume and Dimensional weight of a box?

1. Analysis:

1) Outputs: Box_Volume, Box_D_Weight;

2)Inputs:

Height, length, width;

3) Processing:

1) Box_Volume = height * length * width;

2) Box_D_Weight = (Box_volume + 165)/166;

/* A C program to compute the Volume & Dimensional weight Dimensional weight of a box */ _/ STEP 1: START PART /_

#include <stdio.h>

main()

int height, length, width, Box_Volume,

Box_D_Weight; /declaring variables/

_/ STEP 2: Reading Data/_**

printf("Enter height of box: ");

scanf("%d", &height);

printf("Enter length of box: ");

scanf("%d", &length);

10

printf("Enter width of box: ");

scanf("%d", &width);

*/ * STEP 3: Computation */*

Box_Volume = height * length * width;

Box_D_Weight = (Box_Volume + 165) / 166;

_/ step 4 OUTPUT/_**

printf ("Dimensions: %d x %d x %d \n", length,

width, height);

printf ("Volume (cubic inches): %d \n",

Box_Volume); /* printing expression) */

printf ("Dimensional weight (pounds): %d \n",

Box_D_Weight);

_/ STEP 5 END/_**

return 0;

Benefits of learning C

  • (^) You will be able to read and write code for a large number of platforms -- everything from microcontrollers to the most advanced scientific systems can be written in C, and many modern operating systems are written in C.
  • (^) The jump to the object oriented C++ language becomes much easier. C++ is an extension of C, and it is nearly impossible to learn C++ without learning C first.

C History

  • (^) Developed between 1969 and 1973 along with Unix
  • (^) Due mostly to Dennis Ritchie
  • (^) Designed for systems programming
    • (^) Operating systems
    • (^) Utility programs
    • (^) Compilers
    • (^) Filters

ā€˜Hello World’ in C #include <stdio.h> main() { printf(ā€œHello, world!\nā€); return 0; } #include  C preprocessor command that lets user includes the code from another file (such as a library) stdio.h  standard input/output library #include <stdio.h>  allows you to use code from the standard input/output library that contains printf function

  • (^) main  Every program must have a function named main which contains statements enclosed in braces { and }
  • (^) printf  A function from the standard I/O library that prints a string (f stands for formatted)
  • (^) \n  A new line character. The \n inside the string indicates a new line
  • (^) Every function must return a value. Main is a function and returns a value taken by the operating system as the program terminates
  • (^) return 0  Used to signal OS that the program terminated normally

General C program! # directives main() { statements }

  • (^) Statements  Commands that are carried out as program runs; - (^) printf is a call statement displaying string on screen : - (^) _printf (ā€œhelloā€); / These are comments /_ - (^) _printf (ā€œworld! \nā€); / Can go any where in a C /_
  • Statements end with a semicolon ( ; )

Some definitions

ā€œHello, World!\nā€

  • (^) Character  A single letter, number, punctuation mark, etc.
  • (^) String  Series of characters grouped together;
  • (^) Some special kinds of characters exist:
    • (^) \t – tab character;
    • (^) \n – new line character.