Skip to main content

Posts

Showing posts from April 22, 2021

How to find Power of a number in C

  How to find Power of a number in C: - In this program we will calculate the power of a number using C programming. We want to calculate the power of any given number so you need to multiply that particular number power of time. Ex:- Let suppose number is 2 4  so we need to multiply with 4 times of 2. That is 2*2*2*2=16. ALGORITHMS:- Step 1 – Enter the base number, the number in which you just want to find the power of the number. Step 2 – Enter the exponential, the power of the number. Step 3 – Initialize while loop, while the exponential is not equal to zero.                  (i)  do temp*number and store it in the temp.                   (ii)  now reduce the exponential with -1.                   Here you got the power of the number. Step 4 – Now print the temp variable. Step 5-  Stop. CODE: - #include <stdio.h> int   main () {      int   base , exp = 1 , temp = 1 ;      printf ( "Enter the base value: " );      scanf ( "%d" ,& base );      printf ( &q

How to find a reverse of a given number in c programming

  How to find reverse of a given number in c programming:-   This program reverses a number entered by a user and then prints it. For example, if a user will enter 6577756 as input then 6577756 will be printed as output. This C program accepts an integer and reverses it .   ALGORITHMS:- Step 1 . Take the number which you have to reverse as the input variable says the number. Step 2. Obtain its quotient and remainder. Step 3 . Multiply the separate variable with 10 and add the obtained remainder to it. Step 4 . Do step 2 again for the quotient and step 3 for the remainder obtained in step 4. Step 5.  Repeat the process until the quotient becomes zero. Step 6 . When it becomes zero, print the output and exit. Step 7 . Stop. CODE: - #include <stdio.h> int  main() {      int  num,rev= 0 ,rem;     printf( "Enter any number: " );     scanf( "%d" ,&num);      while (num> 0 )     {       rem= num% 10 ;       rev= rev* 10 +rem;       num=num/ 10 ;     }       p

How to Find the Sum of Digits of a Number without loop in c programming

C Program to Find Sum of Digits of a Number without loop:-   In t his  program, we will calculate the sum  of the number inserted by the user or in an inserted integer.  The program is taken as an input and stored in the variable number, denoted as no. Initially, the sum of the variable is zero, and then  it is divided  by 10  to obtain the result or output.     ALGORITHMS:- Step 1 : Start   Step 2 : Ask the user to insert an integer as an input.   Step 3 :  Divide the integer by 10 in order to obtain the quotient and remainder.   Step 4: Increase the new variable with the remainder received in the above step. Step 5: Repeat the above steps with the quotient till the value of the quotient becomes zero.   Step 6 :  Printf  the output or sum. Step 7 : Stop. CODE: -  #include <stdio.h> int  main() {      int  n,d1,d2,d3,d4,d5,sum;     printf( "enter any num" );     scanf( "%d" ,&n);     d1=n% 10 ;     n=n/ 10 ;     d2=n% 10 ;     n=n/ 10 ;     d3=n% 10 ;