Posts

Showing posts from June, 2015

Convert number from decimal to binary C++ program { Method 2 }

Another method to convert number from decimal to binary. To read another method then go to link convert number from decimal to binary { Method 1 }

Decimal to binary conversion C++ program { Method 1 }

Image
For the conversion of decimal to binary, what we do. We divide number by 2 until we get 0 and then write the remainders. see the image.

Find the second smallest element in array C Program

Simple C program to find second smallest element in unsorted array. C program to find second minimum element in unsorted array.

Find out second largest element in array C program

Find second largest element in given array. For example if arr is {2,6,3,12,7,9,4} then second largest element is 9 . Our task is find out this element.

Differences between string constant and character constant

Here differences between string constant and character constant.

Differences between declaration and initialization in C/C++

Simple definition of declaration and initialization in C/C++. Both are same in C and C++.

3 Simple C programs to check palindrome string

Simple C Program to check palindrome string or whether string is palindrome or not: To check palindrome, declare a variable flag and initialize it to 1 and then compare first element with last element then second element with second last element and so on.

C++ Program to print address of character

Image
Simple C Program to print address of character.

C++ Program to print address of a number

Image
Simple C Program to print address of a number: To print address any number, we use & sign. For example if we want to print address number n=9, then we will &n.

C++ Program to check even or odd numbers

Image
Simple C Program to check whether given number is even or add: To check even or odd number, divide number by 2 and check remainder. If remainder is 0 then number is even otherwise number is odd. For example number 4 is even because when we divide it with 2, we get remainder 0 and number 5 is odd because when we divide it by 2, we get remainder 1.

C++ Program to print array using pointer

Simple C++ program to print array using pointer: We know pointer store the address of the variable and to print the value of address that is stored into pointer variable we use * sign. Suppose pointer is int *ptr and a variable is int n=9. To store address of variable n, we will write ptr=&n. We can print the value of n by n and *ptr. *ptr=n=9.

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++ Program to reverse array

Image
Simple C program to reverse array: In this programming we are swapping array elements. For example we are swapping first element with last element, second element with second last element and so on.

C++ Program to print array reverse

Image
Simple C++ program to print array reverse:

C++ Program to find smallest element in array

Image
Simple C++ program to find smallest element in array: To find smallest element in array, first declare a variable smallest and initialize it to first element of array. Now compare it with all elements of array, if find any element less than smallest then update smallest to that element.

C++ Program to find largest element in array

Image
Simple C program to find largest element in array: To find largest element, first we initialize max (largest element in array) as first element of array and then compare it with all elements of array. If we find any element greater then max then we update max with that array element.

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.

What is Pointer in C Programming

Image
Pointer is a variable which store the address of another variable or the value of a pointer is address of another variable. We declare pointer using * sign that is called asterisk.

C++ Program to compute remainder

Simple C++ Program to compute remainder To compute remainder in C++, there is a operator by which remainder can be computed directly and that is %. For example if two numbers are 12 and 7 then to compute remainder, when we divide 12 by 7, we use 12%7. 12%7 = 5.

C++ Program to print numbers from 1 to n

Simple C++ program to print number from 1 to n .

C++ Program to calculate area of circle

Simple C++ program to calculate area of circle: Area of circle is pi*r*r. We have used this to calculate area of circle.

C++ Program to perform addition subtraction multiplication division

Simple C++ to calculate sum, subtraction, multiplication division: To perform all of these we use operator +,-,/,*.  To print division of two numbers, we use type casting. Typecasting from int to float using (float)number.

C++ Program to print floating point number

Simple C++ Program to print floating point number. To print floating point number is declared as float data type. In C++ to print number we use cout and to get input from keyboard we use cin. These both function are in iostream library io= input, output, i=input, o=output.

C Program to find smallest element of array

Simple C program to find smallest element in array: Here first we define min as 0th element of array. Now we compare it with others element of array. If min is greater than array element than we update it to array element. If min is less than array element then do not update it.

C Program to find largest element of array

Simple C program to find largest element of array. Here is simple C program to find largest element. First we initialize largest element (max) as arr[0]. Then compare it with all elements of array. If we find element greater than max we update it with that element other we do not update.

C Program to check prime numbers using recursion

Simple C Program to check whether a number is prime number or not. A number is called prime number which is divisible only by 1 and itself. For example number 5 is prime number because it is divisible by 1 and 5 but number 8 is not prime number because it is divisible by 2,4.

C Program to find power of a number using recursion

Simple C program to find power of a number using recursion: If number is 4 and its power that we have to find is 3 then program will print 64.

C Program to find sum of digits of a number using recursion

Simple C program to find sum of digits of a number using recursion: To find sum of digits, We have to add all digits one by one. To get digits one by one we have to find remainder of a number when we divide it by 10 and we will add all remainders and will get sum of digits. So if number is 121212 then program will print 9. If number is 12345 then 15.

C Program to count the number of occurrences of an element in array using recursion

Simple C program to count the number of occurrences of an element in array using recursion.

C Program to search element in array using recursion

Simple C Program to search element in array using recursion: If array is {2,8,5,1,8,9,3}; and number is 5 to search then program will print "number is at index 2 or if number is 8 then program will print "number is at index 1" , "number is at index 4". If number is 20 then program will print that number is not in array.

C Program to calculate factorial using recursion

Image
Simple C program to calculate factorial of a number using recursion: Factorial of a number is given by multiplication of 1 to n. For example if number is 5 then factorial of 5 = multiplication of 1 to n numbers = 1*2*3*4*5 = 120. Factorial of 0 is given by 1.

C Program to calculate sum of array element using recursion

Simple C program to find sum of array elements: If array is {10,10,.40,40,7,3} then output of this program will be 110.

C Program to find length of string using recursion

Simple C program to find length of string using recursion: We know that at the end of string there is a null character and null character is denoted by '\0'. So if pointer to string reaches to end of string then function return value 0.