WAP to print the sum of all the PRIME or EVEN integers in the array and ignore the remaining.

Recommended Answers

All 9 Replies

OK. What have you tried so far?

Given an array of random characters, integers and symbols, WAP to print the sum of all the PRIME or EVEN integers in the array and ignore the remaining. Consider consecutive numbers as a single number

Example 1: given the below input the output will be 2+13+8+22=45

Given Input [2GSD#13x8xU343%^DGF1@22@]

Expected output 45

Example 2: given the below input the output will be 11+23+164+44=242

Given Input x11@23@33S164DFS44_+}|#555

Expected output 242

what is code to solve that que...?

what is code to solv

What is WAP? Google says it's " Wireless Appication Protico", but I doubt that's what you are talking about.

If you haven't done something then start coding.

Take user input, Then check that each character is int or not.
Then apply prime no. logic to check wether it is prime or not and then sum it up.

And then with your effort of coding, post specific doubt in it.

What is WAP?

i think OP is newbie and doesn't familiar with daniweb homework policy. He take WAP as Write A Programme , i think.

WAP to print the sum of all the PRIME or EVEN integers in the array and ignore the remaining.

if you think that somebody here will write program for you then i think you are at wrong place ,in order to get assistance you need to prove that you made efforts to solve this question(you can prove this by showing us your code you have so far).

create an array variable and then give input to it. then check each element if they are numbers , if they are numbers then check if they are prime or even number then add the number to a variable(sum+=arr[i]).don't forget to initialize the sum variable to 0.

He take WAP as Write A Programme

Yes -- that makes sense. I'll write the program for him, but first me must deposit $10,000.00 USD in my PayPay account (as I've told others like him)

WAP meanc "Write A Program"

Ancient Dragon ...just give mee hint about that program...

Here you go....

#include <stdio.h>

#define ARR_SIZE 10

int main()
{
    size_t i = 0;
    char chr_arr[ARR_SIZE];

    /*populate int_arr*/

    for (; i < ARR_SIZE; ++i)
    {
        if (chr_arr[i] /*meets some condition*/)
        {

        }
    }
    return 0;
}

Now lets see you write the condition part and populate the array.

One hint that I will provide is that a large amount of your work will be reduced if you use something like strtol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.