You are here

C programs

Symmetric matrix in C

C program to check if a matrix is symmetric or not: First we find transpose of a matrix and then compare it with the original matrix. For a symmetric matrix AT = A.

#include<stdio.h>
#include<conio.h>

main()
{
   int m, n, c, d, matrix[10][10], transpose[10][10];

   printf("Enter the number of rows and columns of matrix\n");
   scanf("%d%d",&m,&n);
   printf("Enter the elements of matrix\n");

   for (  c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
         scanf("%d",&matrix[c][d]);
                 
   for( c = 0 ; c < m ; c++ )
   {

Palindrome number in C

Palindrome number in c: A palindrome number is a number such that if we reverse it, it will not change. For example,some palindrome numbers examples are 121, 212, 12321, -454. To check whether a number is palindrome or not first we reverse it and then compare the number obtained with the original, if both are same then number is palindrome otherwise not. C program for palindrome number is given below.

Palindrome number algorithm

1. Get the number from user.
2. Reverse it.
3. Compare it with the number entered by the user.
4. If both are same then print palindrome number

Remove vowels from a string in C

Remove vowels string C: C program to remove or delete vowels from a string, if the input string is "c programming" then output will be "c prgrmmng". In the program we create a new string and process entered string character by character, and if a vowel is found it isn't added to new string otherwise the character is added to new string, after the string ends we copy the new string into original string. Finally we obtain a string without any vowels.

C programming code

#include <stdio.h>
#include <string.h>

int check_vowel(char);

int main()
{
  char s[100], t[100];

C program to sort a string in alphabetic order

C program to sort a string in alphabetic order: For example,if user will enter a string "programming" then output will be "aggimmnoprr" or output string will contain characters in alphabetical order. In our program we assume input string contains only lower case alphabets.

C programming code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void sort_string(char*);

main()
{
   char string[100];

   printf("Enter some text\n");
   gets(string);

   sort_string(string);
   printf("%s\n", string);

   return 0;
}

void sort_string(char *s)
{
   int c, d = 0, length;
   char *pointer, *result, ch;

Bubble sort in C

Bubble sort

Bubble sort in C to arrange numbers in ascending order; you can modify it for descending order and can also sort strings. The bubble sort algorithm isn't efficient as its both average-case as well as worst-case complexity are O(n2).

Leap year program in C

C program to check leap year: c code to check leap year, year will be entered by the user. Please read the leap year article before reading the code, it will help you to understand the program.

C programming code

#include <stdio.h>

int main()
{
  int year;
 
  printf("Enter a year to check if it is a leap year\n");
  scanf("%d", &year);
 
  if ( year%400 == 0)
    printf("%d is a leap year.\n", year);
  else if ( year%100 == 0)

Insertion sort in C

Insertion sort in C: C program for insertion sort to sort numbers. This code implements insertion sort algorithm to arrange numbers of an array in ascending order. With a little modification it will arrange numbers in descending order.

Insertion sort algorithm implementation in C

/* insertion sort ascending order */

#include <stdio.h>

int main()
{
  int n, array[1000], c, d, t;

  printf("Enter number of elements\n");
  scanf("%d", &n);

  printf("Enter %d integers\n", n);

  for (c = 0; c < n; c++) {
    scanf("%d", &array[c]);
  }

Pages

Subscribe to RSS - C programs