WEEK:2 PROGRAMMING ASSIGNMENT 2 SOLUTION (Jan 2020-Apr2020) An Introduction to Programming through C++ NPTEL 2020

  

               An Introduction To Programming Through C++


IIT Bombay.

Week 2- Programming Assignment 2:


As input, you are given an integer n, a double x, followed by n+1 doubles a_n, a_{n-1}, ..., a_0.  You are to print the value of the polynomial a_0 + a_1x+a_2x^2+...+a_nx^n.

Here is the manual algorithm.  At the beginning you just have read a_n.  Next you read a_{n-1} and calculate a_nx+a_{n-1}.  Next you read a_{n-2} and calculate (a_nx+a_{n-1})x+a_{n-2}.  So after n iterations you will have the value of the polynomial above.  Note that in each iteration you need to use the values calculated earlier.


  InputOutput
Test Case 1
2 3 3 2 1               
 34



#include<iostream>
double mul(double x,int m);
double mul(double x,int m)
{
  double su=1;
  
  for(int i=0;i<m;i++)
  {
    
    su=su*x;
  }
  return su;
}
int main()
{
  
  int n,i,j,m;
  double x,arr[30],sum=0;
  
  
  cin>>n;
  cin>>x;
  
  for(i=0;i<=n;i++)
  {
    cin>>arr[i];
        
  }
  m=n; 
  for(i=0;i<=n;i++)
  {
    sum=sum+arr[i]*mul(x,m);
    m--;    
  }
  
  cout<<sum<<"\n";
return 0;  
}
WEEK :3 QUIZ 1 SOLUTION CLICK ON BELOW LINK.
<<CLICK HERE  FOR WEEK 3 QUIZ 1 ANSWERS>>
FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.

COMMENT IF YOU HAVE ANY PROBLEM WITH THE SOLUTIONS.

Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100%  correct solutions. 

No comments:

Post a Comment

If you have any problems related to solutions or any concept please let me know.

Copyright (c) 2020 Custom Programs All Right Reserved

Pages