in turboc++
----------------------------------------------------------------------------------
//program to enter any five elements and find their sum.
#include<stdio.h>
#include<conio.h>
void sum_of_array(float array[5],int size);//prototype with array and size parameters.array[] also can //be used without size
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
}
sum_of_array(arr,size);//calling of function
getch();
return 0;
}
void sum_of_array(float array[5],int size)//body line
{
int k;float s=0;//declaration
printf("elements are\n");
for(k=0;k<size;k++)//loop execution
{
printf(" element for location=%d is:",k); // for elements in particular location
printf("%f\n",array[k]);//value printing
s=s+array[k];//finding sum
}
printf("the sum of elements=%f",s);//printing sum
getch();
}
---------------------------------------------------------------------------------------------------
in codeblockls:
------------------------------------------------------------------------------------------------
//program to enter any five elements and find their sum.
#include<stdio.h>
#include<conio.h>
void 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
}
sum_of_array(arr,size);//calling of function
return 0;
}
void sum_of_array(float array[5],int size)//body line
{
int k;float s=0;//declaration
printf("elements are\n");
for(k=0;k<size;k++)//loop execution
{
printf(" element for location=%d is:",k); // for elements in particular location
printf("%f\n",array[k]);//value printing
s=s+array[k];//finding sum
}
printf("the sum of elements=%f",s);//printing sum
getch();
}
----------------------------------------------------------------------------------
//program to enter any five elements and find their sum.
#include<stdio.h>
#include<conio.h>
void sum_of_array(float array[5],int size);//prototype with array and size parameters.array[] also can //be used without size
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
}
sum_of_array(arr,size);//calling of function
getch();
return 0;
}
void sum_of_array(float array[5],int size)//body line
{
int k;float s=0;//declaration
printf("elements are\n");
for(k=0;k<size;k++)//loop execution
{
printf(" element for location=%d is:",k); // for elements in particular location
printf("%f\n",array[k]);//value printing
s=s+array[k];//finding sum
}
printf("the sum of elements=%f",s);//printing sum
getch();
}
---------------------------------------------------------------------------------------------------
in codeblockls:
------------------------------------------------------------------------------------------------
//program to enter any five elements and find their sum.
#include<stdio.h>
#include<conio.h>
void 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
}
sum_of_array(arr,size);//calling of function
return 0;
}
void sum_of_array(float array[5],int size)//body line
{
int k;float s=0;//declaration
printf("elements are\n");
for(k=0;k<size;k++)//loop execution
{
printf(" element for location=%d is:",k); // for elements in particular location
printf("%f\n",array[k]);//value printing
s=s+array[k];//finding sum
}
printf("the sum of elements=%f",s);//printing sum
getch();
}
No comments:
Post a Comment