Click here to Skip to main content
15,884,859 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#include <bits/stdc++.h>
using namespace std;
void print(int n)
{
    int var1 = 1, var2 = 1;
    for (int i = 0; i < n; i++) {
        for (int j = n - 1; j > i; j--) {
            cout << " ";
        }
        for (int k = 1; k <= var1; k++) {
            cout << abs(k - var2);
        }
 
        var1 += 2;
        var2++;
        cout << "\n";
    }
}
int main()
{
    int n = 6;
    print(n);
     
    return 0;
}


What I have tried:

please help in doing that to c program
Posted
Updated 1-Apr-22 2:10am
Comments
Richard Deeming 1-Apr-22 5:16am    
This is not a code conversion service.
honey the codewitch 1-Apr-22 8:40am    
Have you considered studying? Imagine you "earned" your degree by way of other people and landed a programming job. Are those other people to do your work for you as well? Maybe if you're going to school, take advantage of it.

The C equivalent of cout is printf[^]. That's the only thing that you need to replace.
 
Share this answer
 
This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and what makes something work in one language does not always "translate" directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can’t be upgraded nicely, and that will cause you immense headaches if the original is changed. And it'll be a nightmare to debug if it doesn’t work "straight out of the box".
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it from scratch using the original as a "template". You will get a much, much better result that will save you a lot of time in the long run.

In this case, since you wrote the C++ code you know exactly how it works, and since C is a subset of C++ it should be trivial for you to replace cout with printf
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900