Posts

Showing posts from July, 2017

C - Functions

Image
C language is a function oriented programming language. When you develop a program ,you can create your own function or you can use existing functions. The main advantage of using a function is re usability. How to use existing functions main() is also a inbuilt function. There are some math library functions are included in C. Let's see how can we use such a function from a example. Output In the above code i have called the math.h library function inorder to call a inbuild math library function. It is the only alternation i have done to this code rather than the examples i have done before. Also by giving as '%.2f ' I have given a limit to display the float value. If i haven't given a limit,the float value will display fully as you can see below. And we should call the function to find the output of the input variable 'v '. Function calling is done at the last printf statement as sqrt(v). The syntax of declaring a function.

C - Arrays

Image
An array is a data structure which can be used to store set of values with similar data types. In C , arrays can be devided into two types. Single Dimensional Arrays Multi Dimensional Arrays Single Dimensional Arrays The declaration form of single dimensional array is, data_type array_name[size]; Ex: int number[5]; float number[5]; In a array index is starting from 0. Therefore the last index is always equals to (size - 1) In the above examples the size is defined to 5 therefore the last index is 4. We can assign values to relative indexes as below. number[0]=10; number[1]=4; number[2]=5; number[3]=47; number[4]=43; Also we can ask users to input numbers for the array and we can display the entered numbers. Let's see how that can happen from a example. Output of the above code.   Multi Dimensional Arrays In multi dimensional arrays, we can find different number of rows and columns. In below I have  explained how to declare a 3 x 4 m

C- Control Structures

A control structure defines the execution order of the given program statements. There are three types of control structures. Sequence (Linear) Selection Repetition (Iteration) Selection Structure In C language we can use the If and Switch statements to represent the selection structure. If statement also come in two ways. 1. if(condition){      statement;    }    else{     statement;    } 2. if(condition){      statement;    }    else if{     statement;    }    else{     statement;    } This second way is called as nested if statement. and also there can be only a if condition in a program. ex:  1. #include <stdio.h> #include <stdlib.h> int main() {     int no1,no2;     printf("enter two numbers");     scanf("%d %d",&no1,&no2);     if(no1>no2){         printf("highest is %d \n",no1);     }     else{         printf("highest is %d \n",no2

C- Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators −       Arithmetic Operators       Relational Operators       Logical Operators       Bitwise Operators       Assignment Operators       Misc Operators Arithmetic Operators + Adds two operands. − Subtracts second operand from the first. * Multiplies both operands. / Divides numerator by de-numerator. % Modulus Operator and remainder of after an integer division. ++ Increment operator increases the integer value by one. -- Decrement operator decreases the integer value by one. Rational Operators == Checks if the values of two operands are equal or not. If yes, then the condition becomes true. != Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. > Checks if the

C ASCII Code

Image
#include <stdio.h> int main() { char chr; printf("Enter a character: "); scanf("%c",&chr);     // When %c text format is used, character is displayed in case of character types printf("You entered %c.\n",chr);  // When %d text format is used, integer is displayed in case of character types printf("ASCII value of %c is %d.", chr, chr);  return 0; } By adding // we can denote a comment in C. In the above example i have described the code inside of it by using comments. The output of the above code

C - Input/Output

Image
#include <stdio.h> int main() {     int testInteger;     printf("Enter an integer: ");     scanf("%d",&testInteger);      printf("Number = %d",testInteger);     return 0; } Above program shows how we can input value to a program and how to print that value entered. %d is used to indicate integer input or output. Same as that we use, %f - float %c or %s - char %f - double

C- Escape Sequences

Sometimes, it is necessary to use characters which cannot be typed or has special meaning in C programming. For example: newline(enter), tab, question mark etc. In order to use these characters, escape sequence is used. For example: \n is used for newline. The backslash ( \ ) causes "escape" from the normal way the characters are interpreted by the compiler. Escape Sequences Character \b Backspace \f Form feed \n Newline \r Return \t Horizontal tab \v Vertical tab \\ Backslash \' Single quotation mark \" Double quotation mark \? Question mark \0 Null character

C-Data Types and Variable Naming

Data Types C supports several different types of data, each of which may be represented differently within the  memory. Some of the data types used in C language are,    int    char    short    double     float Variable Naming Only underscores, letters and digits are allowed in variables.  No special characters allowed other than underscore. First character should be a letter or a underscore. you can't have reserved words as the variable name.            ex: int , char , continue But you can have reserved words as variable name by capitalizing one or more letters in the word.            ex: iNt, conTinue Variable names are case sensitive. And there are constants A constant is a value or an identifier whose value cannot be altered in a program.            ex: 1, 2.5, "C programming is easy", etc. Those values cannot be changed. const double PI = 3.14 Here, PI is a constant. Basically what it means is that

Programming With C Language

Image
First Program In C C  is a high-level and general-purpose  programming language  that is ideal for developing firmware or portable applications. Originally intended for writing system software,  C  was developed at Bell Labs by Dennis Ritchie for the Unix Operating System in the early 1970s. C language is a case sensitive language. To do programming in C first we should install a C editor such as Turbo C,C free,codeblocks etc. In here i am using codeblocks as my editor. But also we can do coding in notepad also.  After installation now we are going to write our first program. open codeblocks get a new empty file and write the code below. #include<stdio.h>← header file int main()← function   ↑ return type {     printf("Hello World \n");     return 0;                     ↑ }                               line break Save this source code as HelloWorld.c(any name you like with .c extension). To convert this source code in to machin