Sunday, October 13, 2024
HomeC Programmingcommon in c programming

common in c programming


Program to seek out the whole and common gross sales of all the worker utilizing array construction

#embody <stdio.h>

struct Worker
{
    char identify[20];
    float sale;
    float common;


};
void foremost()
{

    int no_of_employee;
struct Worker e[no_of_employee];
printf("###Enter the Particulars of Workers###");
printf("nEnter Whole Variety of Workers:");
scanf("%d", &no_of_employee);
int TotalSales = 0;
int i;
for (i = 0; i < no_of_employee; i++)
{
    printf("nEnter the worker Title:");
    scanf("%s", e[no_of_employee].identify);
    printf("nEnter the Whole Variety of Gross sales completed by %s:", e[no_of_employee].identify);
    scanf("%d", &e[no_of_employee].sale);
    TotalSales = TotalSales + e[no_of_employee].sale;

}

printf("Whole Gross sales of  Worker:%d", TotalSales);
//Discovering  Common of gross sales

float Common = (no_of_employee) / TotalSales;
printf("Common gross sales of all the worker:%f", Common);
     
    
}

 On this article we’re going to see learn how to write program common  gross sales of an worker utilizing construction.

so Let’s begin the reason of above program line by line.

Within the first line  of code we’re together with stdio.h header file which can assist us to among the built-in operate’s like printf() and scanf() it should assist us for printing the output on console and taking enter from console respectively.

Within the subsequent line of code, now we have created one construction with identify Worker and with 3 subject identify,gross sales,common through which identify subject is of char(Character) knowledge kind with dimension 20 imply’s our identify can of 20 character.sale is of int(Integer) kind,we are going to use this subject to retailer how a lot sale is finished in numbers and common subject is of float kind and can retailer the typical of sale on this subject.We will create any variety of occasion of this Worker Construction.

from the subsequent line of code,we’re beginning our foremost operate,on this we are going to write our complete programming logic,we are able to additionally say that the principle operate is a place to begin of any c program.

Within the subsequent line of code,now we have declared one variable of kind int with identify no_of_employee,on this variable we’re going to retailer the whole.of worker of whom now we have to retailer knowledge and we  will use this variable in for loop as properly.

Within the subsequent line  code we’re creating e object array of kind Worker with dimension no_of_employee utilizing struct key phrase,right here we’re utilizing much less reminiscence for array through the use of dynamic dimension of e array.

Within the subsequent line,now we have printed one assertion “###Enter the Particulars of Workers###” it should assist person to point that now we have to supply some enter and after this now we have additionally printed yet another assertion “nEnter Whole Variety of Workers:” right here now we have used n as a result of we wish this assertion into the subsequent line and right here the execution will pause since within the subsequent line now we have used scanf(“%d”, &no_of_employee);which can really pause the execution,right here now we have used %d format specifier as a result of we’re storing the enter in variable no_of_employee and of kind int.

Within the subsequent line now we have declared yet another variable TotalSales and assigned 0 to it,On this variable we are going to complete the total_no_sales completed by all worker.Within the subsequent line now we have declared yet another variable i of kind int,we are going to use this variable as a iterative variable in beneath for loop.

from the subsequent line of code now we have used one for loop which can really helps us to take person enter for all worker one after the other 

The pattern worth of no_of_employee = 3

1st Iteration

i=0 //(for i=0 ;i<no_of_employee;i++) The bottom worth of i is 0 and 

0<3 // Situation Glad since i < no_of_employee Due to this fact the management will go contained in the for loop 

Contained in the for loop

printf(“nEnter the worker Title:”);//This assertion will assist person to grasp that now we have present worker identify 

scanf(“%s”, e[no_of_employee].identify);//This assertion will take person enter and retailer it in e[0].identify means this identify shall be saved in 0th index of e and in identify subject of it and right here now we have used %s format specifier as a result of we’re utilizing right here character array which is nothing however labored as string.

 printf(“nEnter the Whole Variety of Gross sales completed by %s:”, e[no_of_employee].identify);//right here we’re printing yet another assertion 

For those who any have doubt,suggestion concerning this put up or web site then be at liberty to share with us.

 

You probably have realized one thing new from this put up then share this put up with your loved ones and
associates.

 

Completely satisfied Studying :)😎  

Earlier

Subsequent

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments