-->
Showing posts with label Program to find sum and average of 10 numbers using pointer.. Show all posts
Showing posts with label Program to find sum and average of 10 numbers using pointer.. Show all posts

Program to find sum and average of 10 numbers using pointer.

using codeblocks
--------------------------------------------------------------------
//program to print sum and average of 10 numbers using pointer. //comment of program
#include <stdio.h>            //header file
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i,k,sum=0;          //variable declaration
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    p=a;                       //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
        sum=sum+*(p+i);   // finds sum
    }
    printf("the sum=%d\n",sum);          // prints sum
    printf("the average =%f\n",(float)sum/total);//prints average
    return 0;
}

--------------------------------------------------------------------------
using turbo c++
------------------------------------------------------------------------------------
//program to print sum and average of 10 numbers using pointer. //comment of program
#include <stdio.h>            //header file
#include<conio.h>
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i,k,sum=0;          //variable declaration
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    p=a;                       //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
        sum=sum+*(p+i);   // finds sum
    }
    printf("the sum=%d\n",sum);          // prints sum
    printf("the average =%f\n",(float)sum/total);//prints average
   getch();
    return 0;
}

---------------------------------------------------------------------------------------------------------
or
----------------------------------------------------
//program to print sum and average of 10 numbers using pointer. //comment of program
#include <stdio.h>            //header file
int main()                   //main function
{
    int a[20],i,sum=0;          //variable declaration
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",a+i);   //gets value for given address , starting from 0. This input goes upto last value of address
        sum=sum+*(a+i);   // finds sum
    }
    printf("the sum=%d\n",sum);          // prints sum
    printf("the average =%f\n",(float)sum/total);//prints average
    return 0;
}