-->
Showing posts with label 4)WAP to input weight of 100 students and count number of students who have weight in between 40 and 60 kg. Pass Weight as an array as parameter.. Show all posts
Showing posts with label 4)WAP to input weight of 100 students and count number of students who have weight in between 40 and 60 kg. Pass Weight as an array as parameter.. Show all posts

WAP to input weight of 100 students and count number of students who have weight in between 40 and 60 kg. Pass Weight as an array as parameter.

in truboc++
-----------------------------------------------------------------------------------------

/*WAP to input weight of 100 students and count number of students who have weight in between 40 and 60 kg.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
int total_nu_of_array(float array[200],int size);//prototype with array and size parameters
int main()
{

float arr[200];int k;            // array declaration with maximum limit 200
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter weights of students\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data/weight inputs
}
printf("total in given range=%d",total_nu_of_array(arr,size));//calling of function
getch();
return 0;
}

int total_nu_of_array(float array[200],int size)//body line
{

int k;//declaration
int count=0;

for(k=0;k<size;k++)//loop execution

{
if(array[k]>40 && array[k]<60)//condition testing
    {
        count++;//counting if the condition is true
    }
}

return count;//returning total count

getch();

}






---------------------------------------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------------------------------------------------
/*WAP to input weight of 100 students and count number of students who have weight in between 40 and 60 kg.
Pass Weight as an array as parameter.*/
#include<stdio.h>
#include<conio.h>
int total_nu_of_array(float array[200],int size);//prototype with array and size parameters
int main()
{

float arr[200];int k;            // array declaration with maximum limit 200
int size;               // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
printf("enter weights of students\n");
for(k=0;k<size;k++)//loop execution
{
   scanf("%f",&arr[k]);//data/weight inputs
}
printf("total in given range=%d",total_nu_of_array(arr,size));//calling of function
getch();
return 0;
}

int total_nu_of_array(float array[200],int size)//body line
{

int k;//declaration
int count=0;

for(k=0;k<size;k++)//loop execution

{
if(array[k]>40 && array[k]<60)//condition testing
    {
        count++;//counting if the condition is true
    }
}

return count;//returning total count

getch();

}