Learn C Online Blog

Create 10 different Random numbers 2

Create 10 different Random numbers

Below is the program in C language that will create and display 10 different random numbers. This program will make use of srand function in C. In order to generate random numbers, srand is usually initialized to some distinctive value. We will also make use of time function as time function will return different value at different time. The value returned by the time function will act as a parameter to srand function. Here is the code… #include #include #include void main() { int i; clrscr(); srand( (unsigned)time( NULL ) ); for (i=0; i<10; i++) printf(“%d “, rand()); printf(“\n”); getch();...

Program to count number of words from a given sentence 11

Program to count number of words from a given sentence

The below mentioned C Program will count number of words from a given sentence. The program will accept a sentence in a character array sen[100]. It will then calculate the number of words and display the result. #include #include #include void main() { char sen[100]; int i, count = 0; printf(“Enter a Sentence : \n”); gets(sen); for (i=0; i<strlen(sen);i++) { if (isspace(sen[i])) { count++; } } printf(“Number of words in the sentence = %d”, ++count); printf(“\n”); getch(); } Also See: Strings in C Programming Language

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...

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