Posts

WAP to find two Complement of a binary number

Write a C program to read binary number from user and find twos complement of the binary number. How to find 2's complement of a binary number in C. Logic to find twos complement of a binary number in C program. Example Input Input binary number: 01101110 Output Twos complement: 10010010 What is twos complement? Wikipedia  states, twos complement of an  N -bit number is defined as the complement with respect to  2 N . It is the result of subtracting the number from  2 N , which in binary is one followed by  N  zeroes. In simple words twos complement can be defined as sum of 1's complement of the binary number and 1. Logic to find twos complement Below is the step by step descriptive logic to find twos complement of a binary string. 1.             Read a binary string from user. Store it in some variable say  binary . 2.         ...

WAP to find one's complement of a binary number

Write a C program to read binary number from user and find one's complement of binary number using loop. How to find 1's complement of a binary number in C programming. Logic to find ones complement of binary number in C program. Example Input Input binary number: 01000011 Output Ones complement: 10111100 What is Ones complement? Ones complement of a binary number is defined as value obtained by inverting all binary bits. It is the result of swapping all 1's to 0's and all 0's to 1's. Logic to find ones complement Below is the step by step logic to find ones complement of binary number. 1.             Read a binary string from user. Store it in some variable say  binary . 2.             Run a loop from 1 to  length of binary string , incrementing 1 in each iteration. The loop structure should look like  for(i=0; i<SIZE; i++)  (whe...

WAP to print Fibonacci series by n terms

Write a C program to print Fibonacci series up to n terms using loop. How to generate Fibonacci series up to n terms using loops in C programming. Logic to print Fibonacci series in a given range in C program. Example Input Input number of terms: 10 Output Fibonacci series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 What is Fibonacci series? Fibonacci series  is a series of numbers where the current number is the sum of previous two terms. For Example:  0, 1, 1, 2, 3, 5, 8, 13, 21, ... , (n-1th + n-2th) Logic to generate Fibonacci series So far we know that we can get next Fibonacci term by adding previous two terms. Let us take this point to derive our logic. Below is the step by step descriptive logic to generate n Fibonacci terms. 1.             Read number of Fibonacci terms from user. Store it in some variable say  terms . 2.             Init...