NPTEL 2021: AN INTRODUCTION TO PROGRAMMING THROUGH C++ WEEK 2 PROGRAMMING ASSIGNMENT 2.2 SOLUTION

int main()
{
int m,n,a[10],t[10],i,j,d,r=0;
  cin>>m>>n; 
  for(i=0;i<n; i++) 
    cin>>a[i]; 
  for(i=0;i<n;i++)
  {
    d=m*a[i]+r; 
    t[i]=d%10;
    r=d/10;
  }
  if (r>0)
    t[i++]=r%10;
  for(j=0; j<i;j++)
    cout<<t[j]<<"\n";

return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *