C program to find the sum of digit of a number. - Data Structure using C

Translate

Wednesday, December 16, 2020

C program to find the sum of digit of a number.

   C program to find the sum of digit of a number.

code👇👇👇👇👇👇👇👇👇


#include<stdio.h>


int main()

{

    int n, r, sum = 0;


    printf("Enter a number: ");

    scanf("%d", &n);


    while(n != 0)

    {

        r = n % 10;

        sum += r;

        n = n / 10;

    }


    printf("sum = %d", sum);


    return 0;

}

output


No comments:

Post a Comment

Introduction to Arrays

  Introduction to Arrays An array is a data structure that allows you to store a collection of elements of the same type. Each element in th...