Title description:
There is a bill of lading, the data items are: product name (MC), unit price (DJ), quantity (SL). Define a structure prut whose members are the above three data. Define a prut type structure array in the main function, enter the value of each element, calculate and output the total amount of the bill of lading.
Input format: The
first line is the number of data items N (N<100), and each subsequent line is a data item. The product name is a string of no more than 100, the unit price is double type, and the quantity is integer type.
Output format:
the total amount of double type.
Input:
4
book 12.5 3
pen 2.5 10
computer 3200 1
flower 47 5
Output:
3497.500000
c language reference code;
#include <stdio.h>
struct prut{
char mc[101];
double dj;
int sl;
};
int n;
int main()
{
scanf("%d",&n);
struct prut a[101];
int i;
double sum=0.0;
for(i=0;i<n;i++)
{
scanf("%s",&a[i].mc);
getchar();
scanf("%lf%d",&a[i].dj,&a[i].sl);
sum+=a[i].dj*a[i].sl;
}
printf("%lf",sum);
return 0;
}
/*
4
book 12.5 3
pen 2.5 10
computer 3200 1
flower 47 5
*/
Java reference code:
import java.util.Scanner;
public class P1101 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
double sum=0;
for(int i=0;i<n;i++)
{
String s=sc.next();
double a=sc.nextDouble();
int b=sc.nextInt();
sum+=a*b;
}
System.out.printf("%.6f", sum);
}
}