Posts

Showing posts from April, 2020

Accepting Input from User

Accepting Input from User :  There are two different ways to accept input from user 1) Accepting input from standard input/output console : Here we first display some message to user about what should be entered as input and then we accept it using scanf (). Scanf() is a built-in function of C language which accepts input. Syntax : scanf("formatspecifier",&var_name); Where format specifier specifies data type of input like %d indicates data is in integer format, %c means data in character, %f means data is float values etc. Let's consider simple C program to calculate addition of two integers given by user #include<studio.h> int main() {    int n1,n2,result;    //to display message to user    printf("Enter two numbers :");    /*accepting two numbers using single scanf statement*/    Scanf("%d%d",&n1,&n2);    result = n1 + n2;    //display addition of numbers    printf("The addition entered numbers is : &q

Structure of a 'C' Program

Structure of a  'C' Program  : Before moving to a programming part let's learn about structure of a 'C' program including what sections are necessary in a program or how to write C program.  To write a C program we need a text editor. C program contains preprocessor instructions, comments, functions, variables, statements and expressions. For example consider simple C program to display message "Good Morning" to user. #include<studio.h> int main() {   //to print data    printf("Good Morning");    return 0; } Here first statement of a program is preprocessor instruction it is used to link our program with standard input output header file (stdio.h is a standard  input output header file). Second line defines main function from where execution of C program begins. Every C program must have main function. Syntax of main() is : int main([int argc, char * argv[]]) {     ______     ______ } Note : [ ] is used t

Comments

Comments in 'C' language:  Comments are used to give guidelines to a user of a program.  Comments are never processed by compiler instead compiler ignores them. Comments can be either single line or multiple line. C supports both single as well as multi line comments. Single line comments starts with //. For example //This is a single line comment Multiple line comments are enclosed or written between /* and */. For example       /* This is             multi line comment*/

Data Types in C

Image
Data Types in C : Data type defines type of a data that can be stored in a variable. Data types in C are categorized as Buit-in data types, user-defined data types and derived data types. They are as follow : Built-in Data Types / Basic Data Types : Integer : Integer data type is used to store numerical values. Range for integer type values is -32768 to 32767. It requires two bytes memory for storing value. It can be further categorized as signed,  unsigned,  short and long. Range and memory requirements changes accordingly. For example 25, 100, 45 etc are integers Character : Character data type is used to store any single character(letter, number or special symbol). The value of character is always enclosed in single quotation. It requires one byte memory per character to store value. For example 'H', 'i', '4' , '@' etc are characters. Float : Float is used to stored floating point values. It ranges from 3.4 e -38 to 3.4 e

Algorithm and Flowchart (Part 2)

Image
Flowchart : Flowchart is a diagrammatic representation of an algorithm. We can also define flowchart as a graphical method to represent sequence of instructions required to perform specific task or to generate solution to a particular problem. Since it is a graphical method it makes use of various symbols they are as follow  1) An oval   :  An oval symbol is also called as Start/Stop symbol. It is used to represent where algorithm starts from or where it is stopped.     2) An arrow :   An arrow symbol or pointed line is used to show sequence of steps or connection between different steps. 3) A parallelogram : Parallelogram is also called as input/output symbol. It is used to represent input accepted by algorithm or an output generated by algorithm. 4) A Rectangle : Rectangle symbol also called as process. It is used to represent process performed by an algorithm. 5) A Diamond : A diamond shape is also called as decision symbol. It is used to represe

Algorithm and Flowchart

Algorithm :  An algorithm is a set of step by step instructions to perform particular task or to generate solution to a particular problem. Characteristics : 1) Input : An algorithm can accept zero or more inputs. It is not compulsory to provide input to the algorithm. For example if we are writing algorithm for displaying general welcome message to user then there is no need to accept any input. Thus algorithm can have zero inputs also.  2) Output :  An algorithm must produce at least one output. If your algorithm does not produces any output then it is of no use. 3) Definiteness :  Each and every instruction mentioned in an algorithm should be clearly specified. Instructions in an algorithm should not generate any ambiguity (confusion) for user. Thus definiteness is an important property of an algorithm. 4) Finiteness : Number of instructions written in an algorithm should be finite or you can say limited. If number of instructions in a set of algorithm is

Difference Between Compiler and Interpreter

Image
Difference Between Compiler and Interpreter:  Even though both Compiler and Interpreter does the same task there is a difference between how they did the task. Let's see this difference .

Compiler and Interpreter

Image
Compiler and Interpreter: Need :   Let's see why we need compiler or interpreter. For example assume that there are three persons A,B,C. Person A knows only English language, Person B knows only Hindi language and Person C knows both English as well as Hindi language. Now, if Person A wants to communicate with Person B then how can they communicate because of language differences. Solution is Person A must first communicate his information to Person C which in turn translate that information in Hindi and then communicate the same to Person B. So it becomes easy for A and  B to communicate with each other using Person C as a mediator. Compiler and Interpreter does the same task between Computer and Human. Since computer is a machine it knows only machine language or binary language (consists only 0's and 1's). Also we human doesn't know machine language but we know C language. Now to communicate with computer in order to give him instructions we must understa

Introduction to C Programming

Image
C a Programming Language  : Before moving C programming first we must know some basic concepts. Do you know what is a language? Why we use language? Basically we all are using different languages to communicate with each other. Right? So we can define language as a communication medium. Using language we can share our ideas and thoughts.  Now next thing we should know is what is a programming? Program is nothing but a set of instructions used to perform specific task and a art of writing program is called programming. Thus C is a language used to write a programs to communicate with a computer. History : C language was invented by Dennis Ritchie at the Bell lab. in 1972 while working on a project of developing UNIX operating system.