Hi Everyone ,
I have 3 questions that need explaination (only explain),then i will try to solve them.

Q1: Let g(x,n) = 1 – x2/2! + x4/4! - … …+(-1)n x2n /(2n)!
Using a loop write a program to calculate g(x,n).

Q2: write a program that accepts a positive integer and gives its prime factorization; that is expresses the integer as a product of primes or indicates that it is a prime.

Q3 is simple if i have numbers ,but in this case i have Character.
Write a program that reads three characters and prints the maximum and the minimum in alphabetical order.

Thanks for your time

Dani AI

Generated

Brief, practical clarifications and safe implementations for each question. was right to flag factorials and character ordering; , instead of an inner factorial loop you can compute each series term from the previous one to keep the code simple and efficient. Below are small, drop-in C++ snippets and cautions.

Q1: compute the series efficiently by updating the term iteratively (no repeated factorial computation, better numeric stability). Use double for term and sum and update with the recurrence that multiplies by -x*x/((2k-1)*(2k)).

double g(double x, int n) {
    double term = 1.0;
    double sum = term;
    for (int k = 1; k <= n; ++k) {
        term *= - (x * x) / ((2.0 * k - 1) * (2.0 * k));
        sum += term;
    }
    return sum;
}

Q2: trial division works well for ordinary inputs. Pull out factor 2 repeatedly, then test odd divisors up to sqrt(remaining). Store each prime with its exponent so output can be formatted as factors with powers. Watch for n <= 1 and for inputs that exceed 64-bit (use big-int or probabilistic methods there).

#include <vector>
#include <utility>

std::vector<std::pair<unsigned long long,int>> factor(unsigned long long n) {
    std::vector<std::pair<unsigned long long,int>> res;
    if (n < 2) return res;
    int cnt = 0;
    while ((n & 1ULL) == 0) { ++cnt; n >>= 1; }
    if (cnt) res.emplace_back(2ULL, cnt);
    for (unsigned long long p = 3; p * p <= n; p += 2) {
        int c = 0;
        while (n % p == 0) { n /= p; ++c; }
        if (c) res.emplace_back(p, c);
    }
    if (n > 1) res.emplace_back(n, 1);
    return res;
}

Q3: characters compare with < and > in C++. For three chars either sort a tiny array or use std::min/std::max. Note comparisons are case-sensitive; use std::tolower first if you want case-insensitive alphabetical order. Reading with operator>> skips whitespace — use std::cin.get() if spaces matter.

#include <array>
#include <algorithm>

std::pair<char,char> minmax3(char a, char b, char c) {
    std::array<char,3> A{a,b,c};
    std::sort(A.begin(), A.end());
    return {A.front(), A.back()};
}

Test with edge cases (large n, negative or 1, mixed-case chars) and validate inputs before processing.

Recommended Answers

All 2 Replies

Q1: do you know what 2! and 4! mean and how to calculate them with pencil & paper? If not then you need to study factorials, which are used in statistics.

Q3: do it just like you would numbers. Lets say you have three characters 'C', 'A' and 'Z'. Which one is the least and which is the largest. If you still don't know then look up their ascii values in any ascii chart.

Yes ,Of course i know factorial.I think i get your idea .Do you mean that i have to do nested for and one of the for statement calculate the factorial.

About ascii chart i don't have any idea .

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.