Category: Programming Examples in C
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();...
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
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...
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...
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...
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”);...