What is the output of the following code? [code] #include<stdio.h> int sum_of_digits(int n) { int sm = 0; while(n != 0)

What is the output of the following code?
Code:
#include<stdio.h>
int sum_of_digits(int n)
{
      int sm = 0;
      while(n != 0)
      {
          sm += n%10;
          n /= 10;
      }
      return sm;
}
int main()
{
      int n = 1234;
      int ans = sum_of_digits(n);
      printf("%d",ans);
      return 0;
}
A. 1
B. 3
C. 7
D. 10
 

Tìm kiếm

Back
Top