Skip to main content

C code to calculate product of even digits of a given number

 C code to calculate product of even digits of a given number


Code Steps:

1. First input the number
2. Now initialize a variable =1, that stores the multiplication 
3. Now start a while loop until number = 0
4. Inside while loop just find out all the digits by finding the remainder & check it if it is divisible by 2 
5. If the number is divisible by 2 then multiply that number with the variable that was initialize = 1
6. At last return the multiplication storing variable. 


C Code Snippet

#include<stdio.h>
int main (){
    int num;
    int product = 1;
    printf("Enter the number: ");
    scanf("%d",&num);
    int temp = num;
    while(num != 0){
       
        int digit = num % 10;
        num = num / 10;
        if(digit%2==0){
            product = digit*product;
        }
    }
    printf("The product of even digits of %d is: %d", temp,product);
    return 0;
}

Input Output


Enter the number: 78254
The product of even digits of 78254 is: 64
Explanation: 8*2*4 = 64

Enter the number: 589
The product of even digits of 589 is: 8
Explanation: 8*1 = 8



Comments

Popular posts from this blog

What is the Difference Between Web Development and Android Development?

 What is the Difference Between Web Development and Android Development? While many people believe that web development and Android development are the same thing, this couldn’t be further from the truth. While both fields involve code and computers, the two actually have significantly different processes, tools, and skillsets required to complete their work. In this article, we’ll explore some of the key differences between web development and Android development in order to help you decide which profession may be better suited to your skill level and interests. Web Development vs Android Development The Ultimate Android vs Web Developers Showdown : There’s a massive amount of discussion around which type of development, web or android, is better. Both sides have passionate proponents who make compelling arguments. We don’t want to get into that argument. Instead, we’re going to look at both types of development and point out some strengths and weaknesses that make each different ...

Frequency Of Elements in an Array

  Algorithm Step 1: Create a map of integer to store key-value pairs. map<int,int> Step 2: Now iterate over all the elements of the array and count their frequency by the help of map Step 3: Now make a iterator for map to iterate over the map items Step 4: This is the final step. Just print all the elements and their frequency stored in map respectively  Code