Posts

Showing posts with the label C Programming

C Program to delete an element from array by element

Image
Simple C program to delete an element from array by element: To delete an element from array, first we will find the position of that element and we will shift element.

C Program to delete an element from array by position

Image
Simple C program to delete element from array: To delete an element from an array, first we will remove element from array and after that we will shift array element towards left.

C Program to insert element in array

Image
Simple C program to insert element in array : To insert element at a particular position,first we have to shift element and then insert element. For example if array is arr[]={12,13,43,27}; then to insert element at position 1 then we have to shift array element towards right and then insert element at position 1.

C Progrma to reverse array using pointer

Image
Simple C program to reverse using pointer:

C Program to print array reverse using pointer

Image
Simple C program to print array reverse: Address of first element of array is given by the name of array. For example if array is arr[3]={1,2,3} then arr is the address of element 1.

C program to print array using pointer

Image
Simple C program to print array using pointer: To print array element using pointer, first we declare a pointer to integer and then we initialize it to address of first element. Address of first element of array is given by the name of array. Suppose array is arr[3]={2,8,3} then address of element 2 is given by arr.

C Program to print address of character using pointer

Image
Simple C program to print address of character using pointer: We know, pointer store the address of another variables like integer variables, character variables. Here we want to print address of character so first we declare a pointer to character and then store the address of character into it. We can also print address using & and to print address, we use %u.

C program to print address of integer using pointer

Image
Simple C program to print address of integer using pointer: We know that pointer stores the address of another variables. To print address of integer, we declare a pointer to integer variable and store the address of integer into it. To print address, we use %u.

C Program to swap numbers using pointer

Image
Simple C program to swap two numbers using pointer. We know, pointer is a variable that store the address of another variables. To swap two numbers, first we store address of both numbers into two pointer to integer variables. Here pointer to integer variables are p and q. After that we change the value of the address of first number and second number.

C Program to add two numbers using pointer

Image
Simple C program to add two numbers using pointer: Pointer is a variable that store the address of another variable. So to add two number, first we store the address of first number into pointer to integer p and address of second number into pointer to integer q. Sum of two numbers will be *p+*q.

C Program to convert number binary to decimal

Image
C Program to convert number from binary to decimal: Binary numbers contain only 0 and 1 and decimal numbers contain 0 to 9 digits. Numbers in binary system are 100, 1010, 11001. Numbers in decimal system are 254, 582.

Common mistakes we do in C programming

Sometimes, when we write a program in C language, we make mistakes and after that we says " Ohh? Why do i get error". So here are some common mistakes, which are made by everyone.

C Program to convert decimal number to binary number

Image
Simple C program to convert decimal number to binary number: Decimal number is base-10 number and binary number is a base-2 number. In binary number, there are only two number 0 and 1 and in decimal numbers, there are 0 to 9 numbers.

C Program to add two 2D arrays elements

Simple C program to add two 2D arrays.

C Program to print two dimensional array

Image
Simple C program to print two dimensional array: To print two dimensional array, we run two for loop. One for one dimension and another for second dimension.

C Program to copy string

Image
Simple C program to copy string: There is a function in <string.h> library to copy one string into another and which is strcpy(). You can directly copy one string into another string using this function. You can copy one by one element from one string to another.

C Program to reverse string

Image
Simple C program to reverse string: In the given example, we swap string elements like first element with last element, second element with second last element and so on. We do this n/2 times or half of array size.

C Program to reverse array

Image
Simple C program to reverse array To reverse array, we swap elements, first element with last element, second element with second last element and so on. You can also reverse array using recursion.

C Program to add two arrays into third array

Image
Simple C Program to add two arrays into third array Here we are going to add two arrays into third array. First we declare and define two arrays. Then we add these two array into third array. For example two arrays are arr1={3,2,5,7} and array second is arr2={7,11,2,9} then third array will be arr3={3,2,5,7,7,11,2,9}.

C Program to calculate sum of array elements

Simple C program to calculate sum of array elements To calculate sum of array elements, first we declare sum and initialize it to 0. Then add array elements one by one.