import requests
# Function to compile and execute C code using Ideone API
def compile_and_execute_c_code(code):
# Set the URL of the Ideone API
url = "https://ideone.com/api/1/compile"
# Set the payload with required parameters (compiler, code, and input)
data = {
"source_code": code,
"compiler_id": 11, # Compiler ID for C language
"input": ""
}
# Send a POST request to the Ideone API
response = requests.post(url, data=data)
# Parse the response JSON and get the output
output = response.json()['output']
# Return the output
return output
# Example code to be compiled and executed
c_code = """
#include<stdio.h>
int main() {
printf("Hello, world!");
return 0;
}
"""
# Call the function to compile and execute the code
output = compile_and_execute_c_code(c_code)
# Print the output
print(output)