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
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.
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.
sir,the above code is showing lots of error
ReplyDeleteDon't copy the whole code only copy the code which is needed in program ,as there are already code present in nptel program.
Deletetime limit exceeds
ReplyDelete