18

C-program Lab 1 Final

Embed Size (px)

DESCRIPTION

C-program Lab 1 Final

Citation preview

  • C languageis a programming language, was developed at Bell Laboratoriesin 1972 by Dennis M. Ritchie.C language was formalized in 1988 by the American National Standard Institute (ANSI)C language has now become a widely used professional language for various reasons:easy to learnstructured languagecompiled on a variety of computer platforms. easy for debugging, testing and maintenance.

  • Include header file sectionmain(){Declaration part (variables or functions etc)Executable part (statements or commands)}

  • #include

    void main(){printf(Hello world);}

  • printf() and scanf() functions are inbuilt library functions in C.These functions are declared and are defined in stdio.h.printf() is used to print character, string, float, integer etc. onto the output screen.scanf() is used to read character, string, numeric data etc. from keyboard.

  • %d- for integer variable.%c- for character%f- for float variable%s- for string variable

  • Letters : A to Z in Capital letters, a to z in Small letters. Digits : 0 to 9 digits.Underscore symbol : _

  • KeywordsIdentifiersStringsConstantsOperators

  • Reserved words which have particular meaning. They cannot be used for any other purpose.Example: int, float, char, long, short, switch, void, while etc.

  • Names used to identify certain program entities (program variables, function names, etc.)

    Example: int my_name; my_name is an identifier used as a program variable.

  • Group of characters, digits, symbols enclosed within quotation marks are called as strings.

    Example: total, Hello.

  • Constants refer to fixed values that do not change during the execution of a program. C supports several types of constants:

    1. Numeric Constantsi) Integer Constants eg : 2, -23, 0.ii) Floating point constants eg: 3.1416, 5.428, 3 x 10 82. Character Constantsi) Single Character Constants eg: A, D, kii) String Constants eg: ABC, C Programming Lab

  • Type of OperatorSymbolic RepresentationArithmetic Operators +, -, *, /, %Relational Operators>, =, >,

  • There are three main categories of data types in C language. They are:

    Sl No:TypesData Types1Basic Data Typesint, char, float, double, void2Derived data typearray, pointers, functions, reference3User Definedenum, structure, union

  • Data typeSize (in bytes)Format Specifierschar1%cshort2%iint 2 or 4 %d or %iunsigned int2 or 4%ulong int4 or 8%ldfloat4%fdouble8%lflong double10%lf

  • a) Syntax:datatype variable_name;Eg:int a; float x,y,z;

    b) Syntax:datatype variable_name = value;Eg:int a=10; float x=5.2;

  • #includeint main(){ int a,b,c;printf(Enter two numbers); scanf(%d%d,&a,&b);c=a+b;printf(Sum=%d,c);return 0;}

  • Exercises:

    1.Write a program to display your Name and Roll Number.2.Find the product and difference of two integers (using printf and scanf). 3.To find the average of two floating numbers (using printf and scanf).