Computer Science, asked by Preetiwari761, 11 months ago

You're given an integer N. Write a program to calculate the sum of all the digits of N. Input The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N. Output Calculate the sum of digits of N.

Answers

Answered by Anonymous
9

Answer:

#include <stdio.h>

#include <stdlib.h>

int main()

{

 int T,N[10], i, sum;

scanf("%d", &T);

for( i = 0 ; i< T ; i++)

{ scanf("%d" , & N[i]);

}

for( i = 0 ; i< T ; i++)

{ sum = 0;

while (N[i] != 0)

  {

      sum = sum + N[i] % 10;

     N[i] = N[i]/10;

  }

  printf("\n %d" , sum);

}

return 0;

}

Answered by arsudhir21
1

Answer:

T = int(input())

for i in range(T):

 N = int(input())

 total = 0

 while (N!=0):

   last_digit = N % 10

   total += last_digit

   N = N//10

 print(total)

Explanation:

Similar questions