Answers for "convert c++ to c"

C++
1

converter c++ to c

#include <iostream>
using namespace std;

int main(){
int k,n,m;
cout<<"Introduceti numar n:";
cin>>n;
cout<<"Introduceti numar k:";
cin>>k;
//daca restul impartirii lui n la k 
//este mai mic decat jumatate din impartitor
if(n%k<=k/2){
//atunci multiplul este cel mai mare multiplu mai mic decat n
m=k*(n/k);
}
else{
//altfel este cel mai mic multiplu mai mare decat n
m=k*(n/k+1);
}
cout<<"Multiplu "<<k<<" cel mai apropriat de "<<n<<" este "<<m;
return 0;
}
Posted by: Guest on November-04-2021
0

convert c++ to c

#include <iostream>
 
using namespace std;
 
int main()
{
 cout << "##  Program Menghitung Gaji Karyawan  ##" << endl;
 cout << "========================================" << endl;
 cout << endl;
 
 string nama;
 char golongan;
 int jam_kerja, upah_per_jam, total_upah;
 
 // proses input
 cout << "Nama Karyawan: ";
 getline(cin,nama);
 
 cout << "Golongan: ";
 cin >> golongan;
 
 cout << "Jumlah jam kerja: ";
 cin >> jam_kerja;
 
 // tentukan jumlah upah per jam berdasarkan golongan
 switch (golongan) {
  case 'A':
    upah_per_jam = 5000;
    break;
  case 'B':
    upah_per_jam = 7000;
    break;
  case 'C':
    upah_per_jam = 8000;
    break;
  case 'D':
    upah_per_jam = 10000;
    break;
  }
 
  total_upah = jam_kerja * upah_per_jam;
 
  // cek apakah jam kerja lebih dari 48 jam
  if ( (jam_kerja - 48) > 0 ) {
     total_upah = total_upah + ((jam_kerja - 48)*4000);
  }
 
  // proses output
   cout << endl;
   cout << nama << " menerima upah Rp." << total_upah << " per minggu";
   cout << endl;
 
 
 return 0;
}
Posted by: Guest on October-21-2021
0

convert c++ to c online

#include <iostream>
#include <string>
#include <map>
#include <vector>

using namespace std;

const int UNKNOWN = -1;

int belongingTo[5005];
vector<vector<int> > travelTo(5005);

int connectGroup(int node, int group)
{
    int &nodeGroup = belongingTo[node];
    int count = 0;
    
    if (nodeGroup == UNKNOWN)
    {
        nodeGroup = group;
        for (int i = 0; i < travelTo[node].size(); ++i)
            count += connectGroup(travelTo[node][i], group);
        
        count += 1;
    }
    
    return count;
}

int main()
{
    map<string, int> nameToPos;
    int C, R;
    string n1, n2;
    
    while (cin >> C >> R, C)
    {
        nameToPos.clear();
        
        for (int i = 0; i < C; ++i)
        {
            cin >> n1;
            nameToPos[n1] = i;
            travelTo[i].clear();
            belongingTo[i] = UNKNOWN;
        }
        
        while (R--)
        {
            cin >> n1 >> n2;
            int p1 = nameToPos[n1], p2 = nameToPos[n2];
            travelTo[p1].push_back(p2);
            travelTo[p2].push_back(p1);
        }
        
        int longest = 0;
        
        for (int i = 0; i < C; ++i)
            longest = max(longest, connectGroup(i, i));
        
        cout << longest << '\n';
    }
}
Posted by: Guest on November-03-2021
0

c++ convert to c online

// C++ program to generate all possible
// valid IP addresses from given string
#include <bits/stdc++.h>
using namespace std;

// Function checks whether IP digits
// are valid or not.
int is_valid(string ip)
{
	// Splitting by "."
	vector<string> ips;
	string ex = "";
	for (int i = 0; i < ip.size(); i++) {
		if (ip[i] == '.') {
			ips.push_back(ex);
			ex = "";
		}
		else {
			ex = ex + ip[i];
		}
	}
	ips.push_back(ex);

	// Checking for the corner cases
	// cout << ip << endl;
	for (int i = 0; i < ips.size(); i++) {
		// cout << ips[i] <<endl;
		if (ips[i].length() > 3
			|| stoi(ips[i]) < 0
			|| stoi(ips[i]) > 255)
			return 0;

		if (ips[i].length() > 1
			&& stoi(ips[i]) == 0)
			return 0;

		if (ips[i].length() > 1
			&& stoi(ips[i]) != 0
			&& ips[i][0] == '0')
			return 0;
	}
	return 1;
}

// Function converts string to IP address
void convert(string ip)
{
	int l = ip.length();

	// Check for string size
	if (l > 12 || l < 4) {
		cout << "Not Valid IP Address";
	}

	string check = ip;
	vector<string> ans;

	// Generating different combinations.
	for (int i = 1; i < l - 2; i++) {
		for (int j = i + 1; j < l - 1; j++) {
			for (int k = j + 1; k < l; k++) {
				check = check.substr(0, k) + "."
						+ check.substr(k, l - k + 2);
				check
					= check.substr(0, j) + "."
					+ check.substr(j, l - j + 3);
				check
					= check.substr(0, i) + "."
					+ check.substr(i, l - i + 4);

				// cout<< check <<endl;
				// Check for the validity of combination
				if (is_valid(check)) {
					ans.push_back(check);
					std::cout << check << '\n';
				}
				check = ip;
			}
		}
	}
}

// Driver code
int main()
{
	string A = "25525511135";
	string B = "25505011535";

	convert(A);
	convert(B);

	return 0;
}

// This code is contributed by Harshit
Posted by: Guest on June-15-2021
-3

c++ to c converter online

123456789101112131415161718192021222324252627#include <iostream>#include <bits/stdc++.h>using namespace std;class ABS{    public:        void abs(int arr[], int n){    sort(arr, arr+n);    int c=0,i;    for (i=n-1;i-2>=0;i--){        if (arr[i-2]+arr[i-1]>arr[i]){            c=1;            break;        }    }    (c) ? cout<<arr[i-2]<<" "<<arr[i-1]<<" "<<arr[i]<<endl : cout<<-1<<endl;}};int main(){    ABS abx;    int arr[] = { 5,4,3,1,2};    int n = sizeof(arr) / sizeof(arr[0]);    abx.abs(arr, n);    return 0;}X
Posted by: Guest on May-28-2021
-1

convert c++ to c online

123456789101112#include <stdio.h>#if !defined (MESSAGE)#define MESSAGE "You wish!"#endifint main(void){cout << "Hello World" << endl;return 0;}X
Posted by: Guest on September-20-2021

Browse Popular Code Answers by Language