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

    

               An Introduction To Programming Through C++


IIT Bombay.

Week 2- Programming Assignment 1:


*Write a program to calculate the total cost from shopping for n commodities.  The input consists of an integer n, followed by n pairs or doubles.  In each pair, the first number is the quantity bought of the commodity, and the second the rate per unit for the commodity.  The amount to be paid for each commodity is the product of the quantity and the rate; the program must print the total over all commodities.  For example if the input is 3 2 30 3 10 5 60, the expected answer is 2*30 + 3*10 + 5*60 = 390.



TEST CASE:

Sample Test Cases
Input                   Output

3 2 30 3 10 5 60            390


#include<iostream>

int main()
{
  int n,sum=0,p[30]={0},i,j=0;
  cin>>n;
  n=2*n;
  for(i=0;i<n;i++)
  {
    cin>>p[i];
  }
  
  for(i=0;p[i]!='\0';i++)
  {
    j=i+1;
    sum=sum+p[i]*p[j];
    i=j;
  }
  cout<<sum<<"\n";
  return 0;
}  

WEEK 3: QUIZ ANSWERS CLICK ON BELOW LINK
<<CLICK HERE FOR WEEK 3 QUIZ ANSWERS>>
WEEK 2: PROGRAMMING ASSIGNMENT 2 SOLUTION
CLICK ON BELOW LINK.
<<CLICK HERE FOR  PROGRAMMING ASSIGNMENT 2 MCQS WEEK 2>>
FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.

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.

3 comments:

  1. sir,the above code is showing lots of error

    ReplyDelete
    Replies
    1. Don't copy the whole code only copy the code which is needed in program ,as there are already code present in nptel program.

      Delete

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

Copyright (c) 2020 Custom Programs All Right Reserved

Pages