Posts

Showing posts from April, 2017

C Program to Swapping Two Numbers

Image
           The two numbers can be swap with the third variable, without third variable or be using bitwise XOR etc. To understand this example you should know Data Types In C Programming and  Operators In C Programming Part: 1 before proceeding further.            Using swap program we can exchange values of two values. Consider your program takes two values as a=5 and b=9 values after swap has become a=9 and b=5.             Let see all methods one by one.       1. Swapping Using Third Variable #include<stdio.h> int main() { int a,b,temp; printf("Enter valude of a and b\n"); scanf("%d %d",&a,&b); printf("a and b before swap are a=%d and b=%d\n",a,b); temp=a; a=b; b=temp; printf("a and b after swap are a=%d and b=%d\n",a,b); return 0; } The ou...

Operators In C Programming Part: 1

Image
            An operator is used to tells the compiler to perform specific mathematical or logical manipulation. Operators are used in the program to manipulate data and variables. The operator needs operand. An operand is a data item on which an operator acts. The operand may be one or more than one. At least one operand is required.            C has a large number of an operator that can be categorized in following groups.   Arithmetic Operators  Relational Operator  Logical Operators Comma Operator  Bitwise Operators sizeof Operators Increment and Decrement Operators Assignment Operators Conditional Operators I will post all operators in 2 parts all with one reference program. In part 1 first 4 operators and in part 2 remaining 4 operators. Let us see one by one operator in detail. 1. Arithmetic Operators  Arithmetic operators are used perform arithmet...

Basic C Programs Part: 1

Image
           At this point, we learn some basic C programs. Firstly I will compare 2 programs and show you how to reduce extra coding and implement the code with the same output. If you did not read my previous article Constants and Variables In C Programming and Data Types In C Programming I suggest you read it first for better understanding before proceeding further.     Program For Basic Mathematical Operations          Let us first see general method(method 1) and the second method(method 2) is a somewhat smart method that can save coding effort and coding time.  Method 1: #include<stdio.h> main() { float a,b,c,d,e,f; printf("Enter value of a and b\n"); scanf("%f %f",&a,&b); //takes two number c=a+b; //Addition d=a-b; //Subtraction e=a*b; //Multiplication f=a/b; //Division printf("Addition is=%f\n",c); ...

Data Types In C Programming

Image
         C Programming supports different types of data types. The different data types require different memory for storage. There four basic data types int, char, float and double.            The 'int' is used to store the integer value, 'char' is used to store any character, 'float' is used to store the floating value and double is used to storing the double value.          Different data types also have a different range. Ranges may vary from compiler to compiler. The below specifiers on 32-bit GCC compiler. Basic Data Types Data Typs withe type qualifiers Size(bytes) Range char signed char 1 -128 to +127 unsigned char 1 0 to 255 int int or signed int 2 -32768 to 32767 unsigned int 2 ...

Structure of C Programs

Image
       In this article, we will see the structure of C programming. How to define and create a C program.          A C program is a collection of one or more functions.The function is a collection of the statement and performs specific task.            C programming language is Procedure Oriented Programming language. The other procedure-oriented programming language is VB, FORTRAN, Pascal. They follow the procedure. It follows Top-Down approach . Importance is not given to data but to functions as well as the sequence of actions to be done. Data can move freely from function to function in the system. In C programming the program can be divided into smaller parts with the help of functions.   C Programming Structure /*Comment Section*/ Preprocessor Directives Global Variables main() { local variables statements ...... Body ...... return 0; } fun...

Constants and Variables In C Programming

Image
          Every programming has some constants and some variables. Likewise, C also has some constants and variables. The constant is an entity that never changes and the variable is an entity that may get change.           The value of the constant in the program never gets change e.g 1,2.5 etc. One thing must remember that the constants and variables must be declared before their use. There are two types of constants. 1. Primary Constant 2. Secondary Constants.            The primary constant constants consist of  Real Constant , Integer Constants and Character Constant . On another hand, the secondary constant consists of Array, Pointer, Structure, Union, Enum etc. In this topic, we see only primary constants only. In a later post, i will tell about secondary constants. For declaring constants it has some rules that are mentioned below.            T...

Introduction to "C" Programming,

Image
              C is a powerful general-purpose programming language. It is fast, portable and available on all platforms.             C is a programming language developed at AT & T's Bell Laboratories of the USA  in 1972. It is designed and written by a man Dennis Ritchie in between 1969 and 1973. It becomes popular its reliable, simple and easy to use. C language suitable for system programmings like an operating system or compiler development.              Nobody can learn C#, C++ or Java directly. C language has some basic elements like classes, polymorphism, exception handling etc. One should learn all the language elements.  The popular operating systems like Windows, Linux, Unix are also written n C.                The C programming language is middle...

Basics of Operating Systems

Image
          The computer is made up of two parts that are hardware and software. If the hardware is not working properly or damaged the computer will not work properly in the similar way to run the computer needs the proper software. There are various software's are available for the computer that is called as operating systems. In a simple way, the operating system is system software used for the proper functioning of a computer. The operating system is an interface between the user and the hardware. It enables the user to communicate with the computer and its peripheral devices.  It is overall manager of the system. It performs all the basic tasks like file management, memory management, process management, handling input and output, and controlling peripheral devices such as disk drives and printers. The operating system may be 32 bit or 64bit.               Everyone uses mobile it is also th...

Patterns In "C" Programming Part: 1

Image
                In "C" programming patterns are very important for understanding the concept of loops. Implementing loops any pattern can be produced. Here are some basic patterns in programming. I am using Linux platform.            Pattern 1 Program #include<stdio.h> main() { int i,j,n; printf("Enter valude of n= "); scanf("%d",&n); for(i=1; i<=n; i++,printf("\n")) { for(j=1; j<=i; j++) { if(j<=i) printf("*"); else printf(" "); } } } The output for n=5 is Pattern 2 Program  #include<stdio.h> main() { int i,j,n; printf("Enter valude of n= "); scanf("%d",&n); for(i=1; i<=n; i++,printf("\n")) { ...