Category: Learn C Online

Program to print binary equivalent of a given decimal integer 7

Program to print binary equivalent of a given decimal integer

Below is the program in C Language that will take decimal number as input. It will then call a function that will calculate the binary equivalent of the input decimal number. #include #include int i = 0; int b[10]; void main() { int dec; int* DecimalToBinary(int n); int *p, j; printf(“Enter a decimal integer = “); scanf(“%d”, &dec); p = DecimalToBinary(dec); printf(“Binary of given decimal integer = “); for (j=i; j>=0; j–) printf(“%d”, p[j]); printf(“\n”); getch(); } int* DecimalToBinary(int n) { while (n != 1) { b[i] = n % 2; n = n / 2; i++; } if (n...

The C Preprocessor Directives 15

The C Preprocessor Directives

The job of the C Preprocessor is to process the source code before it is passed to the compiler. The preprocessor command is also known as directive. The C Program is often called as source code. Before the program is compiled, the source code goes through one process called preprocessor. The preprocessor gets the source code (pr.C file) as input and creates expanded source code (pr.I file). This expanded source code is then passed to the compiler for compilation. Following are the preprocessor directives: Macro expansion File inclusion Conditional Compilation Miscellaneous directives Lets discuss these preprocessor directive one by one....

Compile and Run C Programs using VS 2008 16

Compile and Run C Programs using VS2008

How to Compile and Run C Programs using Microsoft Visual Studio 2008? Here is the answer… In this article I will explain you how to use Visual Studio 2008 to compile and run C program. Compiling and running C Program is as easy as we do in Tourbo C++. Below is the procedure. Please note that the same method applies to Visual Studio 2010 too. So what are waiting for. Read the below article and leave some feedback… Step 1: Go to Start menu->All Programs->Microsoft Visual Studio 2008->Visual Studio Tools->Visual Studio 2008 Command Prompt Following screen will be displayed: Step...

Program to find if a 3 by 3 square matrix is symmetric 14

Program to find if a 3 by 3 square matrix is symmetric

A symmetric matrix is a square matrix that is equal to its transpose. Let A be a symmetric matrix. Then, A = AT In this program, we need to check whether the given square matrix is symmetric or not. We will follow the steps given below. Step 1 – Accepts a square matrix as input Step 2 – Create a transpose of a matrix and store it in an array Step 3 – Check if input matrix is equal to its transpose or not If it is equal, then the input square matrix is symmetric. Here it goes… #include #include...

Program to obtain Transpose of a Matrix 5

Program to obtain Transpose of a Matrix

A transpose of a matrix is formed by turning all the rows of a given matrix into columns and vice-versa. The transpose of matrix A is written as AT Below is the program that will obtain transpose of 3 by 3 matrix. This program takes arr[3][3] matrix as input. It will then display its transpose matrix arrT[3][3]. #include #include void main(){ int arr[3][3], arrT[3][3]; int i,j; clrscr(); printf(“Enter the 3×3 matrix:\n”); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“Enter the element arr[%d][%d] : “,i,j); scanf(“%d”,&arr[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { arrT[j][i] = arr[i][j]; } } printf(“The transpose of the matrix is: \n”);...

Program to perform addition of two 2 by 2 matrix 2

Program to perform addition of two 2 by 2 matrix

An array is a collective name given to a group of similar variables. In this program we will accept two 2-D array (2 by 2 Matrix) as input from the user. This program will then perform addition of two 2 by 2 matrix. It will then display the result after adding two matrix. Here is the program for matrix addition. If you found this article useful, do post a comment. #include #include void main(){ int arr1[10][10], arr2[10][10]; int arr3[][3]={ {0,0,0}, {0,0,0}, {0,0,0} }; int i, j; clrscr(); printf(“Enter 3×3 array 1:\n”); for(i=0;i<3;i++){ for(j=0;j<3;j++){ printf(“Enter element %d x %d:”,i,j); scanf(“%d”,&arr1[i][j]); }...

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet