0

Change c++ into c

Can someone change this code in c++ into c code? // CPP program to print diagonal star patterns #include <iostream> using namespace std;    void pattern(int n) {     // Loop denoting rows     for (int i = 0; i < n; i++) {                    // Loop denoting columns         for (int j = 0; j < n; j++) {                            // Checking boundary conditions and main             // diagonal and secondary diagonal conditions             if (i == 0 || j == 0 || i == j || i == n - 1                              || j == n - 1 || i + j == n - 1)                 cout << "*";             else                 cout << " ";         }         cout << endl;     } }    // Driver code int main() {     // n denotes size which should be odd     int n = 7;     // Function calling     pattern(n);     return 0; }

29th Nov 2019, 4:23 PM
Saba
9 Antworten
+ 6
Saba looks like code is copied from internet as its contain stray especial character which shows when you copied from any source or ide to sololearn. For converting into c all are good by syntax you just need to add printf instead of cout // CPP program to print diagonal star patterns #include <stdio.h> void pattern(int n) {// Loop denoting rows for (int i = 0; i < n; i++) { // Loop denoting columns for (int j = 0; j < n; j++) { // Checking boundary conditions and main // diagonal and secondary diagonal conditions if (i == 0 || j == 0 || i == j || i == n - 1 || j == n - 1 || i + j == n - 1) printf("*"); else printf(" "); } printf("\n"); } } // Driver code int main() { // n denotes size which should be odd int n = 7; // Function calling pattern(n); return 0; } https://code.sololearn.com/cdVy8U02Cpr5/?ref=app
29th Nov 2019, 4:30 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 3
Don't give such questions 1.instead of iostream use stdio.h 2.erase the 2nd line 3.instead of cout use printf
29th Nov 2019, 4:32 PM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 2
Declare int i,j at start of function patterns
29th Nov 2019, 4:35 PM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 2
Then change n in patterns to x
29th Nov 2019, 4:38 PM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
0
Replace the header with- #include<stdio.h> and remove using namespace std; Also replace all your cout with- printf("*"); printf (" "); printf("\n"); This is C.
29th Nov 2019, 4:31 PM
Avinesh
Avinesh - avatar
0
i replaced them already but it just errored
29th Nov 2019, 4:34 PM
Saba
0
it says error:unpaired curly brackets
29th Nov 2019, 4:35 PM
Saba
0
i did
29th Nov 2019, 4:36 PM
Saba
0
Simple Change Header file And instead of cout .printf is used
30th Nov 2019, 2:51 PM
Kagupati.Sampath Raja Raghupathi
Kagupati.Sampath Raja Raghupathi - avatar