Skip to main content

Posts

Calculate the sum of elements in an array.

  HOW TO CALCULATE THE SUM OF THE ELEMENT IN A GIVEN ARRAY: - We will learn how to find the sum of elements in an array is an easy task when you know how to iterate through array elements. In this problem, we will explain your C approach to find the sum of array elements inputted by the user. Here is the solution to this query in C Languageguage.   ALGORITHMS: STEP 1:-   Input the size of the array and store the value in m and arr[m]. STEP 2 : - To store the sum of array elements, initialize a variable sum = 0. STEP 3: -To find the sum of all elements, iterate through each element  and add the current element to the sum. STEP 4: - Inside the loop add the current array element to sum i.e.                 sum = sum + arr[i] or sum += arr[i]. CODE:- #include <stdio.h> int  main() {      int  i,num,a[ 100 ],sum= 0 ;     printf( "Enter the value of number:...

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 ...

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);      ...

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...

Program to find Smallest element in an array using C

  Program to find Smallest element in an array using C We will find the smallest or minimum element in an array using the C concept. We apply an algorithm that assumes the first element as the smallest element and then compares it with other elements if an element is smaller than it then, it becomes the new smallest element, and this process is repeated till the complete array is scanned. ALGORITHMS:-  STEP 1:-    Initialize the required variables. STEP 2:-  Take the input from the user. STEP 3:-   Assume the smallest element is present at the first position. STEP 4:-    Scan each element with the help of for a loop. STEP 5: -    Check if the element Scanned is new smaller than small. STEP 6:-    If it is smallest than small, change the value of small. STEP 7:-    Print small as it stores the smallest element of the array. CODE:- #include <stdio.h> int  main() {      int  a[ 50 ],p,...

How to find ASCII Values of a Character

  How to find ASCII Values of a Character :- ASCII value can be any integer number between 0 and 127 and consists of a character variable instead of the character itself in C programming. The value derived after the programming is termed as ASCII value. With the help of casting the character to an integer, the ASCII value can be derived. Every character has an individual ASCII value that can only be an integer. Every time the character is stored into a variable, as a substitute for keeping the character itself, the ASCII value of the specific character will get stored.  ALGORITHM: - Step 1 : Start Step 2: Ask the user to insert any character Step 3: The character will be assigned to the variable ‘a’ Step 4 : Scan the character variable to find out the ASCII value of the character Step 5 : Stop CODE:- #include<stdio.h> int main() {     char c;     printf( "Enter the value of character:" ); // ent...

How to find the Factor of any number in C

  How to find the Factor of any number in c : - We will calculate the factors of any numbers using C programming. The factors of a number are defined as the number we multiply two numbers and get the original number. The factor of a number is a real number that divides the original completely with zero remainders. ALGORITHM: - Step 1 - Enter the number, to find their factor. Step 2 - Initialise the loop with u=1 to u<=number and follow the following calculation       (i) check whether the number is divisible with u and u got a result zero.       (ii) now print the value of u.  From this loop, u got all the factors of the number. Step 3 - Stop. CODE:- #include<stdio.h> //header file int main() {     int i,num;//variable declaration     printf(" Enter the num to find their factor:  ");     scanf("%d",&num); //to ...