hi! i have a program in C++ that produces a right triangle of character and i need the same program, i mean a program that makes the same function, but in C.
This is my program in C++ :

include <iostream>

using namespace std;
int main()

{
    int i,j;

        char input,temp='A';
        cout<<"Enter uppercase character you want in triange at last row: ";
        cin>>input;
        for(i=1;i<=(input-'A'+1);++i)
        {
            for(j=1;j<=i;++j)
               cout<<temp<<" ";
            ++temp;
            cout<<endl;
        }
        return 0;
    }

please help me :)

Recommended Answers

All 2 Replies

All you have to do is replace cout with printf() and cin with scanf or fscanf. The rest should be the same.

{
    int i,j;
        char input,temp='A';
        printf("Enter uppercase character you want in triange at last row: ");
        scanf("%c",&input);
        for(i=1;i<=(input-'A'+1);++i)
        {
            for(j=1;j<=i;++j)
               printf("%c  ",temp);
            ++temp;
            printf("\n");
        }
        return 0;
    }
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.