C Program Accept n numbers and display the number having the maximum sum of digits - IProgramx

Q. Accept n numbers and display the number having the maximum sum of digits



Program

#include<stdio.h>
#include<math.h>
int main()
{
int x[100],n,max=0,i,j,p,s,q;
printf("enter how many no.:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&x[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i!=j)
{
p=x[i]+x[j];
if(p>max)
{
max=p;
s=i;
q=j;
}
       }
}
}
printf("%d and %d number having the maximum sum of digit is : %d",x[s],x[q],max);
}

Output:

enter how many no.:4
4
2
8
1
4 and 8 number having the maximum sum of digit is : 12

Post a Comment

0 Comments