140 likes | 562 Views
Fundamentals of Computer and programming in C. Programming Languages, Programs and Programming Rohit Khokher. Concepts: Programming Languages, Programs and Programming. Executable. Operation code. Operand. Non-executable.
E N D
Fundamentals of Computer and programming in C Programming Languages, Programs and Programming RohitKhokher
Concepts: Programming Languages, Programs and Programming Executable Operation code Operand Non-executable A set of statements written in a Programming Language and arranged in a specified structure. Machine 101100 10110011 10111010 Assembly ADD A B Programs High level A + B Main programs Sub-programs
Perform • Arithmetic operations • Logical operations • Transfer execution control operations • Cause iteration • Data movement operations • Input devices to memory • Memory to output devices • Memory to memory • Memory to register • Register to memory Executable statements • Declarations (definitions) • Data type declarations • integer data type. • Floating point data type. • Character data type. • Variable declarations • Constant declarations • Program type declarations • Main program • Subprogram Non-executable statement
Structures The structure of a main program in C language Stdio.h is a collection of subprograms for input and output operations like printf (). Preprocessor declarations #include <stdio.h> Type declarations Variable declarations (global) No declaration (empty) Main is an address in the memory. It may contain a data. Void indicates the type of the data will be determined when it will contain a data value. void main () { local declarations Executable statements } void main () { printf (“ \n I am in the main program”); } Function (subprogram) declarations No declaration (empty)
#include <stdio.h> void main () void main () { printf (“ \n I am in the main program”); } PC Code Segment Data address Stdio.h Loader/ Linker/ Binder Loads Codeincodesegment main Printf • Compiler • Checks the syntax • Generates codes DatainDatasegment Data Segment
Algorithm Example • Suppose you are given a set of mark sheets where each mark sheet bears A, B, C or F letter grade. • Write an algorithm to read mark sheet and print the grade that it contains. • Start • Take a mark sheet and read the grade. • Print the grade • Stop #include <stdio.h> void main() { char c; printf ("\n enter the letter grade "); c=getchar(); printf ("\n Grade= "); putchar(c); gets(""); }
Algorithm Example 2 • Suppose you are given a set of mark sheets where each mark sheet bears A, B, C or F grade. Write an algorithm to read a mark sheet and print if the grade is A only. • Start • Take a mark sheet and read the grade. • If grade is A then Print the grade • Stop #include <stdio.h> void main() { // reading and writing characters char c; printf ("\n enter the letter grade"); c=getchar(); if( c =='A') { printf("\n The grade is = "); putchar(c); } }
Algorithm Example 3 • Suppose you are given a set of mark sheets where each mark sheet bears A, B, C or F grade. Write an algorithm to read a mark sheet and print the grade if it is A or B only. • Start • Take a mark sheet and read the grade. • If grade is A or B then Print the grade • Stop #include <stdio.h> void main() { // reading and writing characters char c; printf ("\n enter the letter grade"); c=getchar(); If (( c =='A') | ( c =='B')) { printf("\n The grade is = "); putchar(c); } }
Summary • Structure • Main program • Subprograms (functions) • Blocks • Compilers • Loaders • Linkers • Interpreter s • Program • Main program • Subprogram • Statements • Executable • Non executable • Programming Language • Machine Language • Assembly Language • High level Language