Saturday, 20 May 2017

C/C++ program to find SUM and AVERAGE of two numbers Problem Solution.


C Solution:


#include<stdio.h>
/*
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
void main(){
    int a,b,sum;
    float avg;
    printf("Enter first number :");
    scanf("%d",&a);
    printf("Enter second number :");
    scanf("%d",&b);
    sum = a+b;
    avg = (float)sum/2;
    printf("Sum of %d And %d is %d",a,b,sum);
    printf("\nAverage of %d and %d is = %f",a,b,avg);
}

C++ Solution:

#include<bits/stdc++.h>
using namespace std;
/*
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int a,b,sum;
    float avg;
    cout << "Enter first number :" << endl;
    cin >> a;
    cout << "Enter second number :" << endl;
    cin >> b;
    sum = a+b;
    avg = (float)sum/2;

    cout << "Sum Of " << a << " And " << b << " is " << sum << endl;
    cout << "Average Of " << a << " And " << b << " is " << avg;

    return 0;
}

No comments:

Post a Comment