Sie sind auf Seite 1von 18

COMPUTING & INFORMATICS

www.amiestudy.co m AMIE online

Name : Karthick Loganathan Class Name: Group A - Programming Language

Programming Language
2

Programming Language: Computer program is a set of instructions that guide a computer to execute a particular task. Types of programming language: 1. Low Level Language: The low level language is machine language which consists of instruction and data represented in binary digit (i.e 0 & 1). This is refers to machine code or assembly language. 2. High Level Language: The high level language are programming language which is very close to human, easy understandable. These are categorized as procedural and declarative. A procedural higher level language emphasizes on expression how to do it. A declarative language expresses the feeling what to do Examples: C, C++, Pascal, Java, dot net, etc..
| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
3

The C language was designed in 1972 at the Bell Labs by Denis Ritchie, mainly to rewrite the UNIX operating system in a portable way. The C language was based on previous languages named B and BCPL, and is logically called C to denote the evolution. Why to learn C ? Compact, fast, and powerful Mid-level Language Standard for program development Supports modular programming style
| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
4

#include<stdio.h> // headerfile main() // main function { /* Demo Program */ printf("Sample programe"); }// close braces The purpose of the statement #include <stdio.h> is to allow the use of the function statement like printf scanf to provide program output & input. For each function built into the language, an associated header file must be included C program starting point is identified by the word main(). This informs the computer as to where the program actually starts. The parentheses that follow the keyword main indicate that there are no arguments supplied to this program (this will be examined later on). The two braces, { and }, signify the begin and end segments of the program. In general, braces are used throughout C to enclose a block of statements to be treated as a unit. COMMON ERROR: unbalanced number of open and close curly brackets! printf() is actually a function (procedure) in C that is used for printing variables and text. Where text appears in double quotes , it is printed without modification. The present the \ followed by the n character represents a newline character.

| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
5

Header files contain definitions of functions and variables which can be incorporated into any C program by using the pre-processor #include statement. Standard header files are provided with each compiler, and cover a range of areas: string handling, mathematics, data conversion, printing and reading of variables, etc #include<stdio.h> #include <string.h> #include <math.h> Variables and Expressions Variable Declaration Variables should be declared either outside a function or at the start of a block of code, after the opening {and before any other statements int miles, yards; /* global variables */ main() { float kilometres; /* local variables */ | Computing & Informatics | www.amiestudy.com | AMIE Online Coaching | }

C Language
6

Variable Types There are a number of built-in data types in C. These are listed below char unsigned char signed char int unsigned int long int unsigned long int float double long double

| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
7

Variable Range The range of values that can be stored in variables of these types will depend on the compiler char 0 to 255 or -128 to +127 2 (1 byte) %c unsigned char 0 to 255 (1 byte) %c signed char -128 to 127 (1 byte) %c int -32,768 to +32,767 (2 bytes) %d unsigned int 0 to +65,535 (2 bytes) %u long int -2,147,483,648 to +2,147,483,647 (4 bytes) %ld unsigned long int 0 to 4,294,967,295 (4 bytes) %lu float single precision floating point (4 bytes) %f double double precision floating point (8 bytes) % lf long double extended precision floating point (10 bytes) %Lf
| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
8

#include<stdio.h> #include<conio.h> main() { char a='h'; int b=10; unsigned int c=20; long int d=40; unsigned long int e=60; float f=23; double g=5; long double h=56; clrscr(); printf("\n character =%c",a); printf("\n Interger value =%d",b); printf("\n Unsigned Interger value =%u",c); printf("\n Long Interger value =%ld",d); printf("\n Unsigned long Interger value =%lu",e); printf("\n float value =%f",f); printf("\n Double value =%lf",g); printf("\n Long Double value =%Lf",h); getch(); } | Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
9

Variable Range
Variable and function names (or identifiers) consist of a letter followed by any combination of letters, digits and underscore ( _ ).Upper and lower case letters are distinct, so a and A are different identifiers. int a, A; float b, B;

Assignment
Assignment is the process of storing a value in a variable int a=10; Assignment Operators C has many assignment operators = assign += assign with add -= assign with subtract *= assign with multiply /= assign with divide %= assign with remainder e.g a = a + 17; a += 17;
| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
10

Arithmetic Operators To perform arithmetic operations below operators are used * multiplication / division % remainder after division (modulo arithmetic) + addition - subtraction Increment and Decrement Operators ++ incremental addition --unary subtraction b = 3; a = b++ + 6; /* post increment a = 9, b = 4 */ b = 3; a = ++b + 6; /* pre increment a = 10, b = 4 */ a = b+++c; /* a = (b++) + c */ a = b+ ++c; /* a = b + (++c) */
| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
11

Arithmetic program #include<stdio.h> #include<conio.h> main() { int a=10, b=2, c; clrscr(); printf("\n \t Addition a+b:%d",a+b); printf("\n \t Subraction a-b:%d",a-b); printf("\n \t Multiplication a*b:%d",a*b); printf("\n \t Division a/b:%d",a/b); c=a%b; printf("\n \t Reminder :%d",a%b); getch(); }
| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
12

Incremental & Decremental prg


#include<stdio.h> #include<conio.h> main() { int a=1,b=1,c; clrscr(); printf("\n Pre-Incremental:%d",a++); printf("\n post-incrementl:%d",++b); a=1; b=1; c=a+++b; printf("\n Value of c:%d",c); a=3; b=3; printf("\n post decrement :%d",a--); printf("\n pre decrement :%d",--b); getch(); }
| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
13

Cast Operators
Cast operators allow the conversion of a value of one type to another. (float) sum; converts type to float (int) a; converts type to int
Input and Output Formatted Output printf printf("%f km per hour\n", kilometers); In the program statement above: "%f km per hour\n" is the control string kilometers is the variable to be printed %f is a conversion specifier indicating that the type of the corresponding variable to be printed is float or double
| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
14

Formatted Input scanf scanf is used to interpret characters input to the computer and to store the interpretation in the specified variable(s). scanf("%d", &x); Above line read a decimal integer from the keyboard and store the value in the memory address of the variable x. The & character is vital with arguments. Escape Sequence

Special Characters \a alarm (beep) character \n newline \t horizontal tab \v vertical tab \\ backslash \? question mark \' single quote \" double quote \0 null character

| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
15

Arithmetic program using scanf

#include<stdio.h> #include<conio.h> main() { int a,b; float A,B; clrscr(); printf("\nInteger value"); printf("\nEnter the value for a:"); scanf("%d",&a); printf("\nEnter the value for b:"); scanf("%d",&b); printf("\nFloat value"); printf("\nEnter the value for A:"); scanf("%f",&A);

| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

C Language
16

printf("\nEnter the value for B:"); scanf("%f",&B); printf("\nInteger Value"); printf("\n Addition :%d",a+b); printf("\n Subraction :%d",a-b); printf("\n Multiplication :%d",a*b); printf("\n Division :%d",a/b); printf("\n Reminder :%d",a%b); printf("\nFloat Value"); printf("\n Addition :%f",A+B); printf("\n Subraction :%.2f",A-B); printf("\n Multiplication :%.3f",A*B); printf("\n Division :%.1f",A/B); //printf("\n Reminder :%f",A%B); getch(); }

| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

References
17

Computing & Informatics - Chandwani.Jain.Chaudhari Programming in C - Balaguruswamy

| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

18

Thank You

| Computing & Informatics | www.amiestudy.com | AMIE Online Coaching |

Das könnte Ihnen auch gefallen