You are here

C programs

Subtract matrices

C code to subtract matrices of any order. This program finds difference between corresponding elements of two matrices and then print the resultant matrix.

C programming code

#include<stdio.h>

int main()
{
  int m, n, c, d, first[10][10], second[10][10], difference[10][10];

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

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

  printf("Enter the elements of second matrix\n");

C program to find minimum value in an array

Minimum or smallest value in an array

C program to find the minimum or the smallest element in an array. It also prints the location or index at which it occurs in the list of integers.

How to find smallest number in an array?

Our algorithm assumes the first element as the minimum and then compares it with other elements, if an element is smaller than it then it becomes the new minimum, and this process is repeated till complete array is scanned.

C program remove spaces, blanks from a string

C code to remove spaces or excess blanks from a string, For example,consider the string

"C  programming"

There are two spaces in this string, so our program will print a string
"C programming". It will remove spaces when they occur more than one time consecutively in string anywhere.

C programming code

#include <stdio.h>

int main()
{
   char text[100], blank[100];
   int c = 0, d = 0;

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

   while (text[c] != '\0')
   {
      if (!(text[c] == ' ' && text[c+1] == ' ')) {
        blank[d] = text[c];

C program to delete an element from an array

This program delete an element from an array. Deleting an element does not affect the size of array. It is also checked whether deletion is possible or not, For example,if array is containing five elements and you want to delete element at position six which isn't possible.

C programming code

#include <stdio.h>

main()
{
   int array[100], position, c, n;

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

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

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

C program to insert an element in an array

This code will insert an element into an array, For example,consider an array a[10] having three elements in it initially and a[0] = 1, a[1] = 2 and a[2] = 3 and you want to insert a number 45 at location 1 i.e. a[0] = 45, so we have to move elements one step below so after insertion a[1] = 1 which was a[0] initially, and a[2] = 2 and a[3] = 3. Array insertion does not mean increasing its size i.e array will not be containing 11 elements.

C programming code

#include <stdio.h>
 
int main()
{
   int array[100], position, c, n, value;

Linear search in C

Linear search in C programming: The following code implements linear search ( Searching algorithm ) which is used to find whether a given number is present in an array and if it is present then at what location it occurs.It is also known as sequential search. It is very simple and works as follows: We keep on comparing each element with the element to search until the desired element is found or list ends. Linear search in C language for multiple occurrences and using function.

Linear search c program

#include<stdio.h>

C program to check whether a character is vowel or consonant

This code checks whether an input alphabet is a vowel or not. Both lower-case and upper-case are checked.

C programming code

#include <stdio.h>

main()
{
  char ch;
 
  printf("Enter a character\n");
  scanf("%c", &ch);

  if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch == 'U')
    printf("%c is a vowel.\n", ch);
  else
    printf("%c isn't a vowel.\n", ch);
     
  return 0;
}

Output:

C substring, substring in C

C substring program to find substring of a string and its all substrings. A substring is itself a string that is part of a longer string. For example, substrings of string "the" are "" (empty string), "t", "th", "the", "h", "he" and "e." The header file "string.h" does not contain any library function to find a substring directly.

C substring code

#include <stdio.h>

C program to change case of a string

Here we will change string case with and without strlwr, strupr functions. Strlwr function convert a string to lower case and strupr function convert a string to upper case.

strlwr in c

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

main()
{
    char string[] = "Strlwr in C";
   
    printf("%s\n",strlwr(string));
   
    return  0;
}

strupr in c

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

main()
{
    char string[] = "strupr in c";
   
    printf("%s\n",strupr(string));
   
    return  0;
}

Change string to upper case without strupr

#include<stdio.h>

void upper_string(char*);

main()
{
   char string[100];

Pages

Subscribe to RSS - C programs