A data company wishes to stores it's data files on the server. they wish to store N files. each file has a particular size. the server stores the files in bucket. the bucket id is calculated as the sum of the digits of its file size. the server returns the bucket id for every file request where the file is stored. Write an algorithm to find the bucket id where the files are stored. please write a program in C language.
Answers
Answer:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int n,sum=0,m;
scanf("%d",&n);
int *val = malloc(n*sizeof(int));
for(int i=0;i<n;i++)
{
int sum2 = 0;
scanf("%d",&val[i]);
sum+=val[i];
while(val[i]>0)
{
m=val[i]%10;
sum2=sum2+m;
val[i]=val[i]/10;
}
printf("%i", sum2);
printf(" ");
}
free(val);
}
OR
#include <stdio.h>
int main()
{
int n,val,sum=0,m;
scanf("%d",&n);
while(n--)
{
int sum2 =0 ;
scanf("%d",&val);
while(val>0)
{
m=val%10;
sum2=sum2+m;
val=val/10;
}
printf("%i", sum2);
printf(" ");
}
}