You are on page 1of 1

9.

Write a program that reads a number n, and an array of n numbers and displays the sum of the digits of
each number in the array. Use a subprogram for computing the sum of the digits for a given number.

Sample:

INPUT OUTPUT
4
17 258 95 2 8 15 14 2

1. Programul C++ (in MinGW)

#include<iostream>
uses namespace std;
int scif(int
scif(int a)
{
int s,d,cat,rest;
s=0;
=0;
d=a;
do
{ rest=d%10;
cat=d/10;
s = s + rest;
d=cat;
}
while(cat!=0);
return s;
}

int main()
{
int n, i, v[100], odd;
cin>>n;
for(i=1;i<=n;i++)
cin>>v[i];
for(i=1;i<=n;i++)
cout<<scif(v[i])<<”
scif(v[i])<<” ”;
return 0;
}

You might also like