Get Answers to all your Questions

header-bg qa

Program to print the following series:- 1 333 555557777777....and so on upto nth term.?

Answers (1)

best_answer

// C++ program to print the series 
// 2, 1, 4, 3, 6, 5, …. up to N terms
#include <iostream>
using namespace std;

// Function to print the series
void printPattern(int N)

    for (int i = 1; i <= N; i++)

        // Find and print the ith term
        cout <<" "<<((i % 2 == 0) ? (i - 1) : (i + 1));
    

// Driver code
int main()

    // Get the value of N
    int N = 10;

    // Print the Series
    printPattern(N);

    return 0;

 

Posted by

Deependra Verma

View full answer