C Program for Decimal to Binary Conversion

sudhir sharma
Updated on 19-Aug-2019 11:53:39

1K+ Views

Convert an integer from decimal number system (base-10) to binary number system (base-2). Size of an integer is assumed to be 32 bits, need you to divide the number by the base. It is used by the computer to change integer values to bytes that are a computer.Input:10 Output:1010ExplanationIf the Decimal number is 10When 10 is divided by 2 remainders is zero. Therefore, 0.Divide 10 by 2. New number is 10/2 = 5.when 5 is divided by 2 Remainder is 1. Therefore 1.Divide 5 by 2. New number is 5/2 = 2.when 2 is divided by 2 Remainder is ... Read More

Find the Largest Number Among Three Numbers in C

sudhir sharma
Updated on 19-Aug-2019 11:50:53

832 Views

This program takes the 3 numbers and finds the biggest among all. For this, we will compare the numbers with each other and find out which is the largestInput: a=2,b=4,c=7 Output:7 Largest NumberExplanationThis program uses only if statement to find the largest number.Example#include using namespace std; int main() {    int a,b,c;    a=2,b=4,c=7;    if(a>b) {       if(a>c) {          printf("%d Largest Number ",a);       } else {          printf("%d Largest Number ",c);       }    } else {       if(b>c) {          printf("%d Largest Number ",b);       } else {          printf("%d Largest Number ",c);       }    }    return 0; }

Check Whether a Number is Positive, Negative, or Zero in C

sudhir sharma
Updated on 19-Aug-2019 11:49:19

1K+ Views

A number which is greater than 0 is positive and less than 0 are negative. The concept of positive and negative is very important in number theory and programming also. Calculations rely on this concept only.Input: 0 Output:0 is zeroExplanationUsing conditional statement check the number with 0 weather it is greater than 0 or smaller than 0.Example#include using namespace std; int main() {    int n=0;    if(n>0) {       printf("%d is positive",n);    } else if(n

Check Armstrong Number in C

sudhir sharma
Updated on 19-Aug-2019 11:47:26

440 Views

A number is called an Armstrong number if the sum of cubes of digits of the number is equal to the number itself. It is a mathematical concept usually used in programming to build basic logic of the programmerInput:370 Output:370 is an Armstrong NumberExplanation370 = 3*3*3 + 7*7*7 + 0*0*0 = 27 + 343 + 0 = 370Exampleinclude using namespace std; int main() {    int n, num, rem, sum = 0;    cin >> n;    num = n;    while(num != 0) {       digit = num % 10;       sum += digit * digit * digit;       num /= 10;    }    if(sum == n)       printf("%d is an Armstrong number.", n );    else       printf("%d is not an Armstrong number.",n);    return 0; }

Find Sum of Elements in a Given Array in C++

sudhir sharma
Updated on 19-Aug-2019 11:44:58

1K+ Views

Sum of all Array elements means add all array Elements. Suppose we have 5 Elements in array and we want to find there sum.arr[0]=1 arr[1]=2 arr[2]=3 arr[3]=4 arr[4]=5Sum off all above elements arearr[0]+arr[1]+arr[2]+arr[3]+ arr[4]=1+2+3+4+5=15Input:1,2,3,4,5 Output:15ExplanationUsing For loop to get to the every index element and taking sum of themarr[0]+arr[1]+arr[2]+arr[3]+ arr[4]=1+2+3+4+5=15Example#include using namespace std; int main() {    int i,n,sum=0;    int arr[]={1,2,3,4,5};    n=5;    for(i=0;i

Difference Between Sums of Odd and Even Digits in C

sudhir sharma
Updated on 19-Aug-2019 11:41:47

2K+ Views

Given a number, find the difference between sum of odd digits and sum of even digits. Which means we will be count all even digits and all odd digits and the subtracting their sums.SampleInput:12345 Output:3Explanationthe odd digits is 2+4=6 the even digits is 1+3+5=9 odd-even=9-6=3Taking every digit out of number and checking whether the digit is even or odd if even then add it to even sum if not then to odd sum and then take difference of them.Example#include using namespace std; int main() {    int n, r=0;    int diff =0;    int even=0;    int odd=0; ... Read More

Cube Sum of First N Natural Numbers in C

sudhir sharma
Updated on 19-Aug-2019 11:40:22

590 Views

The cube sum of first n natural numbers is the program to add cubes of all natural numbers up to n. It is sum of series 1^3 + 2^3 + …. + n^3 that is sum of cube of n natural numbers.Input:6 Output:441Explanation1^3 + 2^3 + 3^3 + 4^3 + 5^3 + 63 = 441Using For loop to increase the no. and cubing it and taking sum of them.Example#include using namespace std; int main() {    int n = 6;    int sum = 0;    for (int i = 1; i

HTML DOM Input Text Autofocus Property

AmitDiwan
Updated on 19-Aug-2019 11:40:11

189 Views

The HTML DOM input Text autofocus property is associated with the HTML element’s autofocus attribute. This property is used for setting or returning if the input text field should be automatically focused when the page loads or not.SyntaxFollowing is the syntax for −Setting the autofocus property −textObject.autofocus = true|falseHere, true represents the text field should get focus and false represents otherwise. It is set to false by default.ExampleLet us look at an example for the HTML DOM Input text autofocus property − Input text autofocus property USERNAME: CHECK FOCUS    function FocusVal() { ... Read More

C Program for Compound Interest

sudhir sharma
Updated on 19-Aug-2019 11:39:05

280 Views

Compound interest is the simple interest that is compounded annually i.e. the interest will be calculated and added to the principal amount every year. This increases the overall interest as compared to simple interest. There is a different mathematical formula to calculate the compound interest. Lets see with the an example,Input:p=5, r=4, t=5 Output:1.083263ExplanationCompound Interest = Principle * (1 + Rate / 100)^time CI=5*(1+4/100)^5 CI=1.083263Example#include #include using namespace std; int main() {    float p, r, t, ci;    p=5;    r=4;    t=5;    ci = p * pow((1 + r / 100), t) - p;    printf("%f", ci);    return 0; }

C++ Program for the N-th Fibonacci Number

sudhir sharma
Updated on 19-Aug-2019 11:37:38

854 Views

The Fibonacci sequence is a series where the next term is the sum of the previous two terms.The first two terms of the Fibonacci sequence is 0 followed by 1. In this problem, we will find the nth number in the Fibonacci series. For this we will calculate all the numbers and print the n terms.Input:8 Output:0 1 1 2 3 5 8 13Explanation0+1=1 1+1=2 1+2=3 2+3=5Using For loop to sum of previous two terms for next termExample#include using namespace std; int main() {    int t1=0,t2=1,n,i,nextTerm;    n = 8;    for ( i = 1; i

Advertisements