C C++ program to find average of three numbers using pointer

C C++ program to find average of three numbers using pointer

C Language की विशेषताओं एवं शक्तियों को जानने के लिए देखें—Features and Powers of C

Pointer और इसके कार्य करने के तरीके को आधिक जानने के लिए देखें यह पोस्ट—Pointers in C

Object Oriented Programming (OOP) की विभिन्न अवधारणाओं को जानने के लिए देखें—Concepts of OOP

C program to find average of three numbers using pointer

#include<stdio.h>
int main()
{
    int n1,n2,n3,*p1,*p2,*p3;
    float avg;
    printf("Enter three numbers: ");
    scanf("%d%d%d",&n1,&n2,&n3);
    p1=&n1;
    p2=&n2;
    p3=&n3;
    avg=(*p1+*p2+*p3)/3.0;
    printf("Average = %f",avg);
    return 0;
}

C++ program to find average of three numbers using pointer

#include<iostream>
using namespace std;
int main()
{
    int n1,n2,n3,*p1,*p2,*p3;
    float avg;
    cout<<"Enter three numbers: ";
    cin>>n1>>n2>>n3;
    p1=&n1;
    p2=&n2;
    p3=&n3;
    avg=(*p1+*p2+*p3)/3.0;
    cout<<"Average = "<<avg;
    return 0;
}

Output C C++ program to find average of three numbers using pointer

C C++ program to find average of three numbers using pointer

Useful pointer programs in C C++

  1. Declaration and assignment of pointer
  2. Pointer to pointer
  3. Sum of two numbers using pointer
  4. Swapping two variables using pointer
  5. Pointer Arithmetic
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer