C programming



  • Please find error in the program

    0_1570158322583_20191004_083117.jpg



  • @ajay-chowdhury
    C++ program

    #include <iostream>
    using namespace std;
    int main()
    {
    int n, i;
    float num[100], sum=0.0, average;
    cout << "Enter the numbers of data: ";
    cin >> n;
    while (n > 100 || n <= 0)
    {
    cout << "Error! number should in range of (1 to 100)." << endl;
    cout << "Enter the number again: ";
    cin >> n;
    }
    for(i = 0; i < n; ++i)
    {
    cout << i + 1 << ". Enter number: ";
    cin >> num[i];
    sum += num[i];
    }
    average = sum / n;
    cout << "Average = " << average;
    return 0;
    }

    C program for two number average

    /* c program find sum and average of two numbers*/
    #include <stdio.h>

    int 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)(a+b)/2;
    
    printf("\nSum of %d and %d is = %d",a,b,sum);
    printf("\nAverage of %d and %d is = %f",a,b,avg);
    
    return 0;
    

    }

    Still any doubt , let me know


Log in to reply
 

Powered by dubbtr | @2019

Looks like your connection to dubbtr was lost, please wait while we try to reconnect.