Posts

C Program convert decimal to octal Number

 In this example,we will discuss about how to convert decimal to octal in the c programming language.Following is the solution of the problem. code: #include <stdio.h> #include <math.h> using namespace std; int main() {    int deciNumber,originalnumber;     printf("Enter a decimal number: ");     scanf("%d", &deciNumber);   originalnumber=deciNumber;     int octalnumber = 0, i = 1, remainder;     while (deciNumber != 0)      {            remainder = deciNumber % 8;         deciNumber /= 8;         octalnumber += remainder * i;         i *= 10;     }      printf("%d in decimal = %d in octal", originalnumber, octalnumber);    return 0; } Output: Enter a decimal number: 60 60 in decimal = 74 in octal

C program to convert decimal to binary number

 In this example, we will learn how to convert decimal to binary number system in a c programming language. Following is the solution to the problem. Code: #include <math.h> #include <stdio.h> int main() {     int num,original;     printf("Enter a decimal number: ");     scanf("%d", &num);     original=num;      long long binary = 0;     int remainder, i = 1;     while (num != 0) {         remainder = num % 2;         num /= 2;         binary += remainder * i;         i *= 10;     }     printf("%d in decimal = %lld in binary", original, binary);     return 0;    } Output: Enter a decimal number: 15 15 in decimal = 1111 in binary

C Program to convert binary to decimal number

 In this example, we will learn how to convert the binary to decimal number in the c programming language. Following is the solution to the problem. code: #include <math.h> #include <stdio.h> int main() {     long long num,original;     printf("Enter a binary number: ");     scanf("%lld", &num);     original=num;          int deci = 0, i = 0, remainder;     while (num != 0) {         remainder = num % 10;         num /= 10;         deci += remainder * pow(2, i);         ++i;     }     printf("%lld in binary = %d in decimal", original, deci);     return 0; } Output: Enter a binary number: 111 111 in binary = 7 in decimal

C Program to swap the two numbers

In this example, discuss how to swapping the number in the c programming language. Following is the solution of the problem. Code: #include<stdio.h> int main() {    int firstnum, secondnum, temp;       printf("Enter firstnum number: ");       scanf("%d", &firstnum);       printf("Enter secondnum number: ");       scanf("%d", &secondnum);       // Value of firstnum is assigned to temp       temp = firstnum;       firstnum = secondnum;       // Value of temp  is assigned to secondnum       secondnum = temp;       printf("\nAfter swapping, firstnumNumber = %d\n", firstnum);       printf("After swapping, secondnumNumber = %d", secondnum);       return 0; } Output: Enter firstnum number: 4 Enter secondnum number: 5 After swapping, firstnumNumber = 5 After swapping, secondnumNumber = 4 Here,is another way of swapping the two numbers without using helping variable. Code: swapping the two numbers without helping variable

C program to find the size of variables

 In this example, discuss how to find the size of the variable in c programming language. Following is the code of the problem. Code: #include<stdio.h> int main() {     int intvar;     float floatvar;     double doublevar;     char charvar;     // sizeof is used to find the size of a variable      printf("Size of char: %zu byte\n", sizeof(charvar));     printf("Size of int: %zu bytes\n", sizeof(intvar));     printf("Size of double: %zu bytes\n", sizeof(doublevar));     printf("Size of float: %zu bytes\n", sizeof(floatvar));                return 0; } Output: Size of char: 1 byte Size of int: 4 bytes Size of double: 8 bytes Size of float: 4 bytes

C program to find Ascii value of character

 In this example, discuss how to find the ASCII value of the character in the c programming language. Following is the solution to this problem. code: #include <stdio.h> int main() {       char ch;     printf("Enter a character: ");     scanf("%ch", &ch);            // %d display the integer value(ascii value) of a character     // %c display  actual character     printf("ASCII value of %c = %d", ch, ch);          return 0; } Output: Enter a character: a ASCII value of a = 97 Here,take a character input from the user and display its integer value by using %d in printf.

Tree data structure and its terminology

Image
Why we need a tree data structure? In the array, linked list, stack, and queue data is store in a sequential manner which is difficult to search specific data .the search becomes slow when a huge amount of data stored. This is a very annoying thing in the fast world. All people want to get the result as soon as possible. Different Tree data structures allow to access the data quickly and also it is not a linear data structure. First of all, look at the terminologies of the tree before understanding the concept of the tree. What is a tree? A collection of nodes that are connected by directed edges is known as tree. It is a nonlinear structure as compare to arrays, linked lists, and stacks. Node: A node is a struct that contains a value (data) and stores its pointer. There are two types of nodes internal nodes those nodes which contain at least one child leaf node and external nodes those nodes which are the last. Edge: This is a link between nodes. Root: It is the top most node of a tre