Answers for "convert c++ code to c online"

C++
0

convert c++ code to c online

#include <stdio.h>
#include <math.h>
#define COLUMN 6

void createPattern(char pattern[][COLUMN],int numStudent,int row) {
    for(int i = 0; i < row ; i++) {
        for(int j = 0; j < COLUMN; j++) {
            if(numStudent!=0) {
                pattern[i][j] = 'X';
                numStudent -- ;
            }
            else if(numStudent==0) {
                pattern[i][j] = ' ';
            }
        }
    }
}

void bookSeat(char pattern[][COLUMN],int rowB,int columnB) {
    if(pattern[rowB-1][columnB-1] != ' ') {
        pattern[rowB-1][columnB-1] = 'S';
    }
}

void printPattern(char pattern[][COLUMN],int row) {
    for(int i = 0; i < row ; i++) {
        for(int j = 0; j < COLUMN; j++) {
            printf("%c",pattern[i][j]);
            if(j < COLUMN-1) {
                printf(" ");
            }
        }
        printf("\n");
    }
}
int main() {
    int numStudent,numSeat;
    scanf("%d",&numStudent);
    if(numStudent>=1 && numStudent<=40) {
        int rowBook,columnBook;
        int row = ceil((double)numStudent/COLUMN);
        char pattern[row][COLUMN];
        createPattern(pattern,numStudent,row);

        scanf("%d",&numSeat);

        for(int i = 0 ; i < numSeat ; i++) {
            scanf("%d %d",&rowBook,&columnBook);
            if((rowBook >= 1 && rowBook <= row ) && (columnBook >= 1 && columnBook <= COLUMN)) {
                bookSeat(pattern,rowBook,columnBook);
            }
        }
        printPattern(pattern,row);

    }
    else if(numStudent<1) {
        printf("Students not enough.\n");
    }
    else if(numStudent>40) {
        printf("Too many students.\n");
    }
    return 0;
}
Posted by: Guest on July-17-2021
0

convert c++ code to c online

#include <bits/stdc++.h>
using namespace std;
 
// Function to check if elements are
// pairwise consecutive in queue
bool pairWiseConsecutive(queue<int> q)
{
    // Transfer elements of q to aux.
    stack<int> aux;
    while (!q.empty()) {
        aux.push(q.front());
        q.pop();
    }
 
    // Again transfer the
    // elements of aux to aux2
    stack<int> aux2;
    while (!aux.empty()) {
        aux2.push(aux.top());
        aux.pop();
    }
 
    // Traverse aux2 and see if
    // elements are pairwise
    // consecutive or not. We also
    // need to make sure that original
    // content is retained.
    bool result = true;
    while (aux2.size() > 1) {
 
        // Fetch current top two
        // elements of aux2 and check
        // if they are consecutive.
        int x = aux2.top();
        aux2.pop();
 
        int y = aux2.top();
        aux2.pop();
 
        if (abs(x - y) != 1)
            result = false;
 
        // Push the elements to queue
        q.push(x);
        q.push(y);
    }
 
    if (aux2.size() == 1)
        q.push(aux2.top());
 
    return result;
}
 
// Driver program
int main()
{
    // Pushing elements into the queue
    queue<int> q;
    q.push(4);
    q.push(5);
    q.push(-2);
    q.push(-3);
    q.push(11);
    q.push(10);
    q.push(5);
    q.push(6);
 
    if (pairWiseConsecutive(q))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
 
    // Printing the original queue
    while (!q.empty()) {
        cout << q.front() << " ";
        q.pop();
    }
    cout << endl;
 
    return 0;
}
Posted by: Guest on June-24-2021
0

convert c++ code to c online

include <iostream>
using namespace std;
int main(int argc, char** argv)
{
string s;
int n,c=0,l;
in>>s;
cn>>n;
l=s.length();
while(l%n!=0)
{
s.append("*");
l=s.length();
}
int i=0,t=0;
while(i<l)
    {
    cout<<s[i];
    c++;
    if(c==n)
    {
    c=0;
    cout<<"\n";
    i=i+n;
    t++;
    }
    else
    {
    if(t%2==0)
    i++;
    else
    i--;
    }
}
}
Posted by: Guest on September-29-2021
0

convert c++ code to c online

#include<bits/stdc++.h>
using namespace std;

void printWords(string str)
{
	// word variable to store word
	string word;

	// making a string stream
	stringstream iss(str);

	// Read and print each word.
	while (iss >> word){
		reverse(word.begin(),word.end());
		cout<<word<<" ";
	}
}

// Driver code
int main()
{
	string s = "GeeksforGeeks is good to learn";
	printWords(s);
	return 0;
}
// This code is contributed by Nikhil Rawat
Posted by: Guest on June-14-2021
0

convert c++ code to c online

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    float srednia, suma=0;
    int ilosc_liczb=0; 
    int liczba;

    cout<<"program obliczajacy srednia liczb parzystych (0 – konczy wpis): "<<endl;
    do
    {
        cout<<"Podaj liczbe: ";
        cin>>liczba;
        if (liczba%2!=0 && liczba!=0) // jesli liczba jest nieparzysta
        {
            cout<<"Podaj liczbe: ";
            cin>>liczba;
        }
        if (liczba!=0) //jesli liczba jest jakakolwiek liczba parzysta
        {
            suma=suma+liczba;
            ilosc_liczb++;
        }
    }   
    while(liczba!=0);
    srednia=suma/ilosc_liczb;
    cout<<"Srednia: "<<srednia;
    getch();
    return 0;
}
Posted by: Guest on June-16-2021
0

convert c++ code to c online

#include<stdio.h>
int main()
{
    int x;
    
    /* Print column names */
    printf("Number\tSquare\tCube\n");
    printf("=========================\n");

    for(x=0; x<=20; x++)
        printf("%d\t%d\t%d\n", x, x*x, x*x*x);
    
    return 0;
}
Posted by: Guest on September-04-2021
0

convert c++ code to c online

#include <bits/stdc++.h>
using namespace std;
main() {
	int t,n;
	int j=1;
	cin>>t;
	while(t--){
		cin>>n;
		cout<<"#"<<j<<" ";
		for(int i=0;i<n;i++){
			cout<<"SVMC"<<" ";
		}
		j++;
		cout<<endl;
	}
}
Posted by: Guest on October-14-2021
0

convert c++ code to c online

#include<iostream>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a>0 && b>0){
            cout<<"Solution";
        }
        else if(a==0 && b>0){
            cout<<"Liquid";
        }
        else if(b==0 && a>0){
            cout<<"Solid";
        }
        cout<<endl;
    }
}
Posted by: Guest on October-04-2021
0

convert c++ code to c online

c program
Posted by: Guest on June-15-2021
0

convert c++ code to c online

public class Mythread {

    public static void main(String[] args) {
        Runnable r = new Runnable1();
        Thread t = new Thread(r);
        t.start();
        Runnable r2 = new Runnable2();
        Thread t2 = new Thread(r2);
        t2.start();
    }
}

class Runnable2 implements Runnable{
    public void run(){
        for(int i=0;i<11;i++){
            if(i%2 == 1)
                System.out.println(i);
        }
    }
}

class Runnable1 implements Runnable{
    public void run(){
        for(int i=0;i<11;i++){
            if(i%2 == 0)
                System.out.println(i);
        }
    }
Posted by: Guest on June-26-2021
0

convert c++ code to c online

public class Mythread {

    public static void main(String[] args) {
        Runnable r = new Runnable1();
        Thread t = new Thread(r);
        t.start();
        Runnable r2 = new Runnable2();
        Thread t2 = new Thread(r2);
        t2.start();
    }
}

class Runnable2 implements Runnable{
    public void run(){
        for(int i=0;i<11;i++){
            if(i%2 == 1)
                System.out.println(i);
        }
    }
}

class Runnable1 implements Runnable{
    public void run(){
        for(int i=0;i<11;i++){
            if(i%2 == 0)
                System.out.println(i);
        }
    }
Posted by: Mustafa Ertan on February-09-2022

Browse Popular Code Answers by Language