Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CSC 202 Computer Programming Alphabets of C Recall the alphabets of English language A to Z of English alphabet a to z 0 to 9 + - * / = % & # ! ? ^ “ ‘ ~ \ | < > { } ( ) [ ] : ; . , (blank space) CSC 202 Computer Programming Escape sequence: Special characters Character New line (example: typing) Horizontal tab (example: typing) Vertical tab Backslash Apostrophe Quotation mark Form feed printf(“Hello \n world”); printf(“hello \t world”); Escape Sequence \n \t \v \\ \’ \” \f CSC 202 Identifier Computer Programming name of Variable name of Function Rules in naming an Identifier: • First character of an Identifier must be a letter. “, ‘ • Some characters cant be used. These are -, Examples of some valid identifiers: Examples of some Invalid identifier , x, x12, sum, sum_add, temperature, AREA , tax_rate, 5sum, add”ition, Order-no, Order no Sum, SUm, a, a1, b , B , etc. CSC 202 Computer Programming Keywords ~ are reserved and can’t be used as identifier. C Keywords auto extern for struct continue do void sizeof char int goto union double break switch default return static else if case typedef long unsigned short while Data type C supports several types of data – – – – – Integer (2,3,4); int Long integer (50000); long Floating point numbers (1.2, 5.6); float Long float numbers (100000.56787); double Character (a,b,c,d) Variable is data container. So at the time of variable declaration, we have to mention which type of data is going to contain. ( #include<stdio.h> #include<conio.h> void main(){ int a, b, sum; a=2; b=3; sum=a+b; Variable declaration Input Process printf(“Jogfol is %d \n”,sum); getch(); } Output CSC 202 Computer Programming Variable declaration int a; int b = 56; float temperature; int num = 32767; float temperature=32.5; long bigNum =40040; double fraction = 12 e-3; char ch; char ch =‘A’; CSC 202 Computer Programming Data type Data type Description int Integer (positive & negative) 2 bytes unsigned int long int Positive Integer Long integer 2 bytes 4 bytes float Floating point number 4 bytes double Double precision floating point number Single character 8 bytes char Typical memory requirements 1 bytes #include<stdio.h> #include<conio.h> void main(){ int num1= -23,num2=32767; unsigned int pos1 =23,pos2=65535; float div=3.4; double bigNum=1.2e23; printf(“Integers :\t %d %d \n”,num1,num2); printf(“Positive numbers:\n %u %u \n”,pos1,pos2); printf(“Floating point number:\t %f \n”,div); printf(“Very Big number %lf \n”,bigNum); getch(); } CSC 202 Computer Programming Array Suppose you need to store a record which has thousand of integers. Now will you declare thousand variables???? Array is a solution to such situation. It is an identifier that refers to a collection of data items. Data items must all be of same type. Scores 55 99 77 89 110 27 68 int scores[8]= {55,99,77,89,110,27,68,69}; Or int scores[8]; scores[0]=55; scores[1]=99; 69 #include<stdio.h> #include<conio.h> void main(){ int scores[8]= {55,99,77,89,110,27,68,69}; int pitScore; int bobScore,noBall; printf(“Border-Loyd champ trophy\n”); printf(“----------Score Card------------\n”); printf(“Pit \t %d of %d\n”,scores[0],scores[1]); bobScore= scores[2]; noBall=scores[3]; printf(“Bob \t %d of %d\n”,scores[2],scores[3]); getch(); } Library function • Carries out various commonly used operation or calculation. Example: printf() , getch() , clearscr(), sqrt(), cos(), sin(), tolower(). toupper() Header file: Contains information about Library functions and must be specified in the program. printf() stdio.h sqrt(), cos(), sin() math.h getch(), clrscr() conio.h tolower(), toupper() ctype.h CSC 202 Computer Programming Character encoding • Computer stores and processes data in Binary number system. • Each character and number are given a binary sequence To 10101001 Exam Controller, 111100110100110 Primeasia Uni. 100010000111001 Sub: ….. Stored as 11111101110111 Dear sir, 111010101010101 ……….. 1101001010 C:\application.doc CSC 202 Computer Programming Character encoding Character & number are given a binary sequence following a standard. Standards are: • American Standard Code for Information Interchange (ASCII) • Extended Binary Coded Decimal Information (EBCDI) • Universal Code (UniCode) C programming Language follows ASCII. CSC 202 Computer Programming To ASCII Exam Controller, Primeasia Uni. • Each character is encoded in 7 bits • 128 (27) different characters can be represented Sub: ….. Dear sir, ……….. Character Binary sequence Decimal equivalent or ASCII value A B 20 1000001 1000010 0010100 65 66 20 **Full ASCII list is in the book