Monday, February 28, 2011

Arrays

Production and Sales Analysis

#include <stdio.h>
void main()
{
int M[5][6],S[5][6],C[6],Mvalue[5][6],Svalue[5][6],Mweek[5],Sweek[5],
Mproduct[6],Sproduct[6],Mtotal,Stotal,i,j,number;
clrscr();
printf("Enter products manufactured week_wise \n");
printf("M11,M12,---,M21,M22,--etc\n");
for(i=1;i<=4;i++)
for(j=1;j<=5;j++)
scanf("%d",&M[i][j]);
printf("Enter products sold week_wise\n");
printf("S11,S12,--,S21,S22--etc\n");
for(i=1;i<=4;i++)
for(j=1;j<=5;j++)
scanf("%d",&S[i][j]);
printf("Enter cost of each product\n");
for(j=1;j<=5;j++)
scanf("%d",&C[j]);
for(i=1;i<=4;i++)
for(j=1;j<=5;j++)
{
Mvalue[i][j]=M[i][j]*C[j];
Svalue[i][j]=S[i][j]*C[j];
}
for(i=1;i<=4;i++)
{
Mweek[i]=0;
Sweek[i]=0;
for(j=1;j<=5;j++)
{
Mweek[i]+=Mvalue[i][j];
Sweek[i]+=Svalue[i][j];
}
}
for(j=1;j<=5;j++)
{
Mproduct[j]=0;
Sproduct[j]=0;
for(i=1;i<=4;i++)
{
Mproduct[j]+=Mvalue[i][j];
Sproduct[j]+=Svalue[i][j];
}
}
Mtotal=Stotal=0;
for(i=1;i<=4;i++)
{
Mtotal+=Mweek[i];
Stotal+=Sweek[i];
}
printf("\nFollwing is the list of things you can\n");
printf("Request for Enter appropriate item number\n");
printf("and press RETURN key\n");
printf("1.Value matrices of production & sales\n");
printf("2.Total value of weekly production & sales\n");
printf("3.Product_wise monthly value of production &");
printf("sales\n");
printf("4.Grand total value of production & sales\n");
printf("5.Exit\n");
number=0;
while(1)
{
printf("\nENTER YOUR CHOISE:");
scanf("%d",&number);
printf("\n");
if(number==5)
{
printf("G O O D  B Y E\n\n");
break;
}
switch(number)
{
case 1:
printf("VALUE MATRIX OF PRODUCTION\n\n");
for(i=1;i<=4;i++)
{
printf(" Week(%d)",i);
for(j=1;j<=5;j++)
printf("%7d",Mvalue[i][j]);
printf("\n");
}
printf("\nVALUE MATRIX OF SALES\n\n");
for(i=1;i<=4;i++)
{
printf(" Week(%d)\t",i);
for(j=1;j<=5;j++)
printf("%7d",Svalue[i][j]);
printf("\n");
}
break;
case 2: 
printf("TOTAL WEEKLY PRODUCTION & SALES\n\n");
printf("              PRODUCTION   SALES\n");
printf("              -----------  ---- \n");
for(i=1;i<=4;i++)
{
printf(" Week(%d)\t",i);
printf("%7d\t%7d\n",Mweek[i],Sweek[i]);
}
break;
case 3: 
printf("PRODUCT WISE TOTAL PROCUTION & SALES\n\n");
printf("                   PRODUCTION  SALES\n");
printf("                   ----------  ---- \n");
for(j=1;j<=5;j++)
{
printf(" Product(%d)\t",j);
printf("%7d\t%7d\n",Mproduct[j],Sproduct[j]);
}
break;
case 4:
printf(" GRAND TOTAL OF PRODUCTION & SALES\n");
printf("\n Total production = %d\n",Mtotal);
printf(" Total sales = %d\n",Stotal);
break;
default:
printf("Wrong choice, select again\n\n");
break;
}
}
printf("Exit from the program\n\n");
getch();
}
OUTPUT
Enter products manufactured week_wise
M11,M12,----,M21,M22, ----etc
11 15 12 14 13
13 13 14 15 12
12 16 10 15 14
14 11 15 13 12
Enter products sold week_wise
S11,S12,----,S21,S22,---- etc
10 13 9   12 11
12 10 12 14 10
11 14 10 14 12
12 10 13 11 10
Enter cost of each product
10 20 30 15 25

Following is the list of things you can
request for. Enter appropriate item number
and press RETURN key
1.Value matrices of production & sales
2.Total value of weekly production & sales
3.Product_wise monthly value of product  & sales
4.Grand total value of production & sales
5.Exit
ENTER YOU CHOISE: 1
VALUE MATRIX OF PRODUCTION
Week(1)     110  300  360  210  325
Week(2)     130  260  420  225  300
Week(3)     120  320  300  225  350
Week(4)     140  220  450  185  300
VALUE MATRIX OF SALES
Week(1)     100  260  270  180  275
Week(2)     120  200  360  210  300
Week(3)     110  280  300  210  300
Week(4)     120  200  390  165  250
ENTER YOUR CHOISE: 2
TOTAL WEEKLY PRODUCTION & SALES
                               PRODUCTOIN     SALES
Week(1)                         1305                1085
Week(2)                         1335                1140
Week(3)                         1315                1200
Week(4)                         1305                1125
ENTER YOU CHOISE: 3
PRODUCT_WISE TOTAL PRODUCTION & SALES
                                            PRODUCTION     SALES    
Product(1)                                  500                   450
Product(2)                                1100                   940
Product(3)                                1530                 1320
Product(4)                                  855                   765
Product(5)                                1275                 1075
ENTER YOU CHOISE: 4
GRAND TOTAL OF PRODUCTION & SALES
Total production    = 5260
Total sales        = 4550
ENTER YOUR CHOISE: 5
G O O D  B Y E
Exit from the program

No comments:

Post a Comment