in turboc++
-----------------------------------------------------------------------------------------
//program to enter any five elements and find their sum.
#include<stdio.h>
#include<conio.h>
int sum_of_array(float array[5],int size);//prototype with array and size parameters
int main()
{
float arr[20];int k; // array declaration with maximum limit 20
int size; // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
for(k=0;k<size;k++)//loop execution
{
printf("enter element for location=%d\n",k); // for elements in particular location
scanf("%f",&arr[k]);//data inputs
}
printf("the sum=%d",sum_of_array(arr,size));//calling of function
getch();
return 0;
}
int sum_of_array(float array[5],int size)//body line
{
int k;float s=0;//declaration
for(k=0;k<size;k++)//loop execution
{
s=s+array[k];//finding sum
}
return s;//returning sum(s)
getch();
}
------------------------------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------------------------
//program to enter any five elements and find their sum.
#include<stdio.h>
#include<conio.h>
int sum_of_array(float array[5],int size);//prototype with array and size parameters
int main()
{
float arr[20];int k; // array declaration with maximum limit 20
int size; // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
for(k=0;k<size;k++)//loop execution
{
printf("enter element for location=%d\n",k); // for elements in particular location
scanf("%f",&arr[k]);//data inputs
}
printf("the sum=%d",sum_of_array(arr,size));//calling of function
return 0;
}
int sum_of_array(float array[5],int size)//body line
{
int k;float s=0;//declaration
for(k=0;k<size;k++)//loop execution
{
s=s+array[k];//finding sum
}
return s;//returning sum(s)
getch();
}
-----------------------------------------------------------------------------------------
//program to enter any five elements and find their sum.
#include<stdio.h>
#include<conio.h>
int sum_of_array(float array[5],int size);//prototype with array and size parameters
int main()
{
float arr[20];int k; // array declaration with maximum limit 20
int size; // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
for(k=0;k<size;k++)//loop execution
{
printf("enter element for location=%d\n",k); // for elements in particular location
scanf("%f",&arr[k]);//data inputs
}
printf("the sum=%d",sum_of_array(arr,size));//calling of function
getch();
return 0;
}
int sum_of_array(float array[5],int size)//body line
{
int k;float s=0;//declaration
for(k=0;k<size;k++)//loop execution
{
s=s+array[k];//finding sum
}
return s;//returning sum(s)
getch();
}
------------------------------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------------------------
//program to enter any five elements and find their sum.
#include<stdio.h>
#include<conio.h>
int sum_of_array(float array[5],int size);//prototype with array and size parameters
int main()
{
float arr[20];int k; // array declaration with maximum limit 20
int size; // says about size of array to be entered
printf("enter size of array\n");
scanf("%d",&size);//input of size
for(k=0;k<size;k++)//loop execution
{
printf("enter element for location=%d\n",k); // for elements in particular location
scanf("%f",&arr[k]);//data inputs
}
printf("the sum=%d",sum_of_array(arr,size));//calling of function
return 0;
}
int sum_of_array(float array[5],int size)//body line
{
int k;float s=0;//declaration
for(k=0;k<size;k++)//loop execution
{
s=s+array[k];//finding sum
}
return s;//returning sum(s)
getch();
}
No comments:
Post a Comment