Answer to Question #189627 in C++ for Diksha Jain

Question #189627

wap to input 8 no.s in an integer array and print those no.s whose last digit is perfect no.

wap to input 10 numbers in an array and print the frequency of each number


1
Expert's answer
2021-05-05T15:45:59-0400
#include <iostream>
using namespace std;
bool is_Perfect(long long int n)
{
    long long int sum = 1;
    for (long long int i=2; i*i<=n; i++)
    {
        if (n%i==0)
        {
            if(i*i!=n)
                sum = sum + i + n/i;
            else
                sum=sum+i;
        }
    }
     if (sum == n && n != 1)
          return true;
  
     return false;
}
int main(){
    int n, perfect[8], size = 0;
    cout<<"Input the 8 numbers;\n";
    for(int i = 0; i < 8; i++){
        cin>>n;
        if(is_Perfect(n)){
            perfect[i] = n;
            size++;
        }
    }
    if(size == 0) cout<<"No perfect numbers found!";
    else{
        cout<<"Perfect numbers: ";
        for(int i = 0; i < size; i++) cout<<perfect[i]<<" ";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    int numbers[10], freq[10], x, size = 0;
    bool flag = false;
    cout<<"Enter 10 numbers\n";
    for(int i = 0; i < 10; i++) freq[i] = 0;
    for(int i = 0, k = 0; i < 10; i++){
        cin>>x;
        for(int j = 0; j < i; j++){
            if(x == numbers[j]){
                flag = true;
                freq[j]++;
                break;
            }
        }
        if(flag){
            flag = false;
            continue;
        }
        else{
            numbers[k] = x;
            freq[k]++;
            size++;
            k++;
        }
    }
    cout<<"Number\tFrequency\n";
    for(int i = 0; i < size; i++){
        cout<<numbers[i]<<"\t"<<freq[i]<<endl;
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS