Find sum of entered digits & print largest sum – C

C program to read array of 3 integers, calculate the sum of their digits and print largest sum.

Solution:

#include<stdio.h>
#include<stdio.h>
int main()
{
     int l, n[3], i, large;
     int s1=0,s2=0,s3=0;
     printf("Enter Three Numbers:\n\n");
     for(i=0;i<3;i++)
     {
          scanf("%d",&n[i]);
     }
     printf("\nSum of Digits:\n");
     printf("-------------------");
     for(i=0; i<3; i++)
     {
          int s=0;
          while(n[i]>0)
          {
               l=n[i]%10;
               s=s+l;
               n[i]=n[i]/10;
          }
          if(i==0)
          {
               s1=s;
               printf("\nFirst Number  = %d\n",s1);
          }
          if(i==1)
          {
               s2=s;
               printf("Second Number = %d\n",s2);
          }
          if(i==2)
          {
               s3=s;
               printf("Third Number  = %d\n",s3);
          }
     }
     printf("-------------------");
     if((s1>s2) && (s1>s3))
     {
          large = s1;
     }
     else if(s2>s3)
     {
          large = s2;
     }
     else
     {
          large = s3;
     }
     printf("\nLargest Sum = %d\n", large);
     return 0;
}


Output:

largest-sum