What's new

Closed patulong po c++

Status
Not open for further replies.

Social12

Honorary Poster
Joined
Feb 26, 2018
Posts
322
Reaction
22
Points
188
Hi po mga sir patulong po ako nitong problem may code napo ako pero di gumagana
Input N integers(Ask from the user how many nos. he/she wants to input). Determine and print the sum of all nos., the average of all numbers, how many odd nos. were inputted, how many even nos. were entered and how many zeroes inputted.
Output:
Enter desireed number to input: 6
Input 6 integers:
25
0
-5
12
0

The sum of all nos is 132
The Average of all nos is 32.00
Od nos inputted: 2
Even nos inputted:2
Zero nos inputted:2
 
post code para matulungan ka namin kung anong problem ng code mo at matuto ka sa mistakes mo. no spoonfeeding.
 
ito lang po code ko di ko po alam sir sorry po
#include<stdio.h>
#include<conio.h>

int main(){

int num,ctr;

printf("Enter desired numbers to input:");
scanf("%d",&num);
while (ctr<=num){
printf("Input %d integers\n",&num);

}


return 0;
}
 
ito lang po code ko di ko po alam sir sorry po
#include<stdio.h>
#include<conio.h>

int main(){

int num,ctr;

printf("Enter desired numbers to input:");
scanf("%d",&num);
while (ctr<=num){
printf("Input %d integers\n",&num);

}


return 0;
}
problem is you haven't implemented anything, anyway.

dynamic memory implementation incase you need the values separately later
C++:
#include <stdio.h>

// no error checking implemented. hf

int main()
{
    int nCount = 0, nTotal = 0, nOdd = 0, nEven = 0, nZero = 0;
    printf("Entered desired number to input:");
    scanf("%d", &nCount);

    const int* pInput = new int[nCount];

    if (!pInput)
        return 1;

    printf("Input %d integers: ", nCount);

    for (int idx = 0; idx < nCount; idx++)
    {
        scanf("%d", pInput + idx);
        nTotal += pInput[idx];
        if (pInput[idx] == 0)
            nZero++;
        else
            (pInput[idx] & 1 ? nOdd : nEven) += 1;
    }

    printf(
        "The sum of all nos is %d\n"
        "The Average of all nos is %f\n"
        "Od nos inputted: %d\n"
        "Even nos inputted: %d\n"
        "Zero nos inputted:%d",
        nTotal, static_cast<float>(nTotal) / nCount, nOdd, nEven, nZero
    );

    delete[] pInput;
    return 0;
}

input and parse implementation, values entered are non retrievable / reusable
C++:
#include <stdio.h>

// no error checking implemented. hf

int main()
{
    int nCount = 0, nTotal = 0, nOdd = 0, nEven = 0, nZero = 0;
    printf("Entered desired number to input:");
    scanf("%d", &nCount);

    printf("Input %d integers: ", nCount);

    for (int idx = 0; idx < nCount; idx++)
    {
        int curr = 0;
        scanf("%d", &curr);
        nTotal += curr;
        if (curr == 0)
            nZero++;
        else
            (curr & 1 ? nOdd : nEven) += 1;
    }

    printf(
        "The sum of all nos is %d\n"
        "The Average of all nos is %f\n"
        "Od nos inputted: %d\n"
        "Even nos inputted: %d\n"
        "Zero nos inputted:%d",
        nTotal, static_cast<float>(nTotal) / nCount, nOdd, nEven, nZero
    );

    return 0;
}
 
Last edited:
Code:
#include <iostream>
using namespace std;

int main()
{
    //declaration
    int num;
    int sum = 0;
    double average = 0.0;
    int odd = 0;
    int even = 0;
    int zeros = 0;
    //asking  n integers and initialize integer array
    cout<<"Enter desired number to input: ";
    cin>>num;
    int integers[num];
    cout<<"Input "<<num<<" integers:"<<endl;
    //asking integer inputs
    for(int i=0; i < num; i++)
    {
        cin>>integers[i];
        cout<<endl;
    }
    //display inputs
    for(int i=0; i < num; i++)
    {
        cout<<integers[i]<<" ";
    }
    cout<<endl;
    
    //sums of no. & if odd or even or zero
    for(int i=0; i < num; i++)
    {
        sum = sum + integers[i];
        if(integers[i] == 0)
        {
            zeros = zeros + 1;
        }
        else if(integers[i]%2 == 0)
        {
            even = even + 1;
        }
        else{
            odd = odd + 1;
        }
    }
    //average of all no.
    average = sum / double(num);
    
    //display output
    cout<<"The sum of all nos is "<<sum<<endl;
    cout<<"The average of all nos is "<<average<<endl;
    cout<<"Odd nos inputted: "<<odd<<endl;
    cout<<"Even nos inputted: "<<even<<endl;
    cout<<"Zeros nos inputted: "<<zeros;
    
   return 0;
}
 
Status
Not open for further replies.

Similar threads

Back
Top