id
stringlengths
16
16
language
stringclasses
3 values
category
stringclasses
38 values
question
stringlengths
2
1.96k
answer
stringlengths
1
1.46k
messages
listlengths
2
2
teacher
stringclasses
5 values
batch
stringclasses
20 values
source
stringclasses
677 values
used_in_chat
stringclasses
3 values
tokens
int64
8
849
a274582673018cd3
en
code_c
is this char a letter or digit? C program
This program reads one character and says whether it is a letter, a digit, or neither. ```c #include <stdio.h> #include <ctype.h> int main(void) { int ch; printf("Enter a character: "); ch = getchar(); if (ch == EOF) { return 0; } if (isalpha((unsigned char)ch)) { printf("'%c' i...
[ { "role": "user", "content": "is this char a letter or digit? C program" }, { "role": "assistant", "content": "This program reads one character and says whether it is a letter, a digit, or neither.\n```c\n#include <stdio.h>\n#include <ctype.h>\n\nint main(void) {\n int ch;\n printf(\"Enter...
beam-free
qa-v1
train
216
a1e4151f5e5fd623
en
code_c
how do i reverse a string in c? give me a small program
This program reads a string and prints it reversed. ```c #include <stdio.h> #include <string.h> int main(void) { char text[256]; size_t len; size_t i; printf("Enter a string: "); if (fgets(text, sizeof(text), stdin) == NULL) { return 0; } text[strcspn(text, "\n")] = '\0'; len ...
[ { "role": "user", "content": "how do i reverse a string in c? give me a small program" }, { "role": "assistant", "content": "This program reads a string and prints it reversed.\n```c\n#include <stdio.h>\n#include <string.h>\n\nint main(void) {\n char text[256];\n size_t len;\n size_t i;...
beam-free
qa-v1
train
257
bac0de11996482b8
en
code_c
factorial of a number in c please
This program reads a non-negative integer and prints its factorial. ```c #include <stdio.h> int main(void) { int n; if (scanf("%d", &n) != 1 || n < 0) { return 0; } long long fact = 1; for (int i = 2; i <= n; i++) { fact *= i; } printf("%d! = %lld\n", n, fact); return...
[ { "role": "user", "content": "factorial of a number in c please" }, { "role": "assistant", "content": "This program reads a non-negative integer and prints its factorial.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n\n if (scanf(\"%d\", &n) != 1 || n < 0) {\n return 0;\n ...
beam-free
qa-v1
train
165
619f7e086c9652e2
en
code_c
convert seconds to hours minutes seconds C
This program converts a total number of seconds into hours, minutes and seconds. ```c #include <stdio.h> int main(void) { long total; if (scanf("%ld", &total) != 1) { return 0; } if (total < 0) { total = 0; } long h = total / 3600; long m = (total % 3600) / 60; long s = ...
[ { "role": "user", "content": "convert seconds to hours minutes seconds C" }, { "role": "assistant", "content": "This program converts a total number of seconds into hours, minutes and seconds.\n```c\n#include <stdio.h>\n\nint main(void) {\n long total;\n if (scanf(\"%ld\", &total) != 1) {\...
beam-free
qa-v1
train
207
cc70102971c5877c
en
code_c
can you reverse a string in c pls
This program reads a line, reverses it in place, and prints the reversed string. ```c #include <stdio.h> #include <string.h> int main(void) { char s[100]; if (fgets(s, sizeof(s), stdin) == NULL) { return 0; } size_t len = strlen(s); if (len > 0 && s[len - 1] == '\n') { s[len - 1] ...
[ { "role": "user", "content": "can you reverse a string in c pls" }, { "role": "assistant", "content": "This program reads a line, reverses it in place, and prints the reversed string.\n```c\n#include <stdio.h>\n#include <string.h>\n\nint main(void) {\n char s[100];\n\n if (fgets(s, sizeof(...
beam-free
qa-v1
train
248
333c073dccd07bf2
en
code_c
string length in c without strlen please
This program finds the length of "Hello" without using strlen. ```c #include <stdio.h> int main(void) { char s[] = "Hello"; int len = 0; while (s[len] != '\0') { len++; } printf("Length: %d\n", len); return 0; } ``` Compile and run it; it prints Length: 5.
[ { "role": "user", "content": "string length in c without strlen please" }, { "role": "assistant", "content": "This program finds the length of \"Hello\" without using strlen.\n```c\n#include <stdio.h>\n\nint main(void) {\n char s[] = \"Hello\";\n int len = 0;\n while (s[len] != '\\0') {...
beam-free
qa-v1
train
114
e7f94dfe04a85501
en
code_c
how to check if number even or odd in c
This program reads an integer and says whether it is even or odd. ```c #include <stdio.h> int main(void) { int n; printf("Enter a number: "); scanf("%d", &n); if (n % 2 == 0) printf("%d is even\n", n); else printf("%d is odd\n", n); return 0; } ``` Compile it with gcc -std=c11 -Wall -Wextra and...
[ { "role": "user", "content": "how to check if number even or odd in c" }, { "role": "assistant", "content": "This program reads an integer and says whether it is even or odd.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n printf(\"Enter a number: \");\n scanf(\"%d\", &n);\n ...
beam-free
qa-v1
train
146
edfd5c14ac36e203
en
code_c
write a c program that checks if a char is a letter or a digit
This program reads one character and says whether it is a letter, a digit, or neither. ```c #include <stdio.h> #include <ctype.h> int main(void) { char ch; if (scanf(" %c", &ch) != 1) return 0; if (isalpha((unsigned char)ch)) printf("%c is a letter.\n", ch); else if (isdigit((unsigned char)ch))...
[ { "role": "user", "content": "write a c program that checks if a char is a letter or a digit" }, { "role": "assistant", "content": "This program reads one character and says whether it is a letter, a digit, or neither.\n```c\n#include <stdio.h>\n#include <ctype.h>\n\nint main(void) {\n char c...
beam-free
qa-v1
train
192
db942910141199d9
en
code_c
can u write a c prog that sums an array and gives average?
This program adds the numbers in a fixed array and prints their sum and average. ```c #include <stdio.h> int main(void) { int values[] = {10, 20, 30, 40, 50}; int count = sizeof(values) / sizeof(values[0]); int sum = 0; for (int i = 0; i < count; i++) { sum += values[i]; } double aver...
[ { "role": "user", "content": "can u write a c prog that sums an array and gives average?" }, { "role": "assistant", "content": "This program adds the numbers in a fixed array and prints their sum and average.\n```c\n#include <stdio.h>\n\nint main(void) {\n int values[] = {10, 20, 30, 40, 50};...
beam-free
qa-v1
train
214
c32c087f9adc35bc
en
code_c
write a c program that checks if a number is even or odd
This program reads an integer and prints whether it is even or odd. ```c #include <stdio.h> int main(void) { int n; if (scanf("%d", &n) != 1) { return 0; } if (n % 2 == 0) { printf("%d is even\n", n); } else { printf("%d is odd\n", n); } return 0; } ``` Compile wi...
[ { "role": "user", "content": "write a c program that checks if a number is even or odd" }, { "role": "assistant", "content": "This program reads an integer and prints whether it is even or odd.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n\n if (scanf(\"%d\", &n) != 1) {\n ...
beam-free
qa-v1
train
153
6543209df76f2096
en
code_c
c code to count words in a sentence
This program reads a sentence and counts the words in it. ```c #include <stdio.h> int main(void) { char s[200]; int words = 0, in_word = 0, i = 0; printf("Enter a sentence: "); if (fgets(s, sizeof(s), stdin) == NULL) { return 0; } while (s[i] != '\0') { if (s[i] == ' ' || s[i] =...
[ { "role": "user", "content": "c code to count words in a sentence" }, { "role": "assistant", "content": "This program reads a sentence and counts the words in it.\n```c\n#include <stdio.h>\n\nint main(void) {\n char s[200];\n int words = 0, in_word = 0, i = 0;\n printf(\"Enter a sentenc...
beam-free
qa-v1
train
245
5d23ac56513cf38f
en
code_c
simple menu loop that reads choises in c
This program shows a small menu and reacts to the chosen number until you pick 0. ```c #include <stdio.h> int main(void) { int choice = -1; while (choice != 0) { printf("1. Hello\n2. Bye\n0. Quit\nChoice: "); if (scanf("%d", &choice) != 1) { printf("bad input\n"); return...
[ { "role": "user", "content": "simple menu loop that reads choises in c" }, { "role": "assistant", "content": "This program shows a small menu and reacts to the chosen number until you pick 0.\n```c\n#include <stdio.h>\n\nint main(void) {\n int choice = -1;\n while (choice != 0) {\n ...
beam-free
qa-v1
train
230
0a5f601c817a3767
en
code_c
how do i find the smallest number in an array in c
This program finds the smallest number in a fixed array. ```c #include <stdio.h> int main(void) { int a[] = {5, 2, 9, 1, 7}; int n = sizeof(a) / sizeof(a[0]); int min = a[0]; for (int i = 1; i < n; i++) { if (a[i] < min) min = a[i]; } printf("Smallest number is %d\n", min); return ...
[ { "role": "user", "content": "how do i find the smallest number in an array in c" }, { "role": "assistant", "content": "This program finds the smallest number in a fixed array.\n\n```c\n#include <stdio.h>\n\nint main(void) {\n int a[] = {5, 2, 9, 1, 7};\n int n = sizeof(a) / sizeof(a[0]);\...
beam-free
qa-v1
train
189
0103e883d7105cdb
en
code_c
reverse a string c program
This program reads a word and prints it reversed. ```c #include <stdio.h> #include <string.h> int main(void) { char str[100]; if (scanf("%99s", str) != 1) { return 0; } size_t len = strlen(str); for (size_t i = 0; i < len / 2; i++) { char tmp = str[i]; str[i] = str[len - ...
[ { "role": "user", "content": "reverse a string c program" }, { "role": "assistant", "content": "This program reads a word and prints it reversed.\n```c\n#include <stdio.h>\n#include <string.h>\n\nint main(void) {\n char str[100];\n\n if (scanf(\"%99s\", str) != 1) {\n return 0;\n ...
beam-free
qa-v1
train
195
d2bffe94778f0c4f
en
code_c
hello world in c
This program prints the classic greeting. ```c #include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; } ``` Compile it with gcc and run it. It prints "Hello, world!".
[ { "role": "user", "content": "hello world in c" }, { "role": "assistant", "content": "This program prints the classic greeting.\n```c\n#include <stdio.h>\n\nint main(void) {\n printf(\"Hello, world!\\n\");\n return 0;\n}\n```\nCompile it with gcc and run it. It prints \"Hello, world!\"." ...
beam-free
qa-v1
train
69
8b91bbda7512aaba
en
code_c
average of numbers entered by user in c
This program reads a count and then that many numbers, then prints their average. ```c #include <stdio.h> int main(void) { int count; if (scanf("%d", &count) != 1 || count <= 0) { printf("enter a positive count\n"); return 0; } double sum = 0.0; for (int i = 0; i < count; i++) { ...
[ { "role": "user", "content": "average of numbers entered by user in c" }, { "role": "assistant", "content": "This program reads a count and then that many numbers, then prints their average.\n```c\n#include <stdio.h>\n\nint main(void) {\n int count;\n\n if (scanf(\"%d\", &count) != 1 || co...
beam-free
qa-v1
train
240
33bc72386f0c142f
en
code_c
write c code to count from 10 down to 1
This program counts from 10 down to 1. ```c #include <stdio.h> int main(void) { int i; for (i = 10; i >= 1; i--) { printf("%d\n", i); } return 0; } ``` Compile it with gcc -Wall -Wextra and run it; it prints the numbers 10 through 1.
[ { "role": "user", "content": "write c code to count from 10 down to 1" }, { "role": "assistant", "content": "This program counts from 10 down to 1.\n```c\n#include <stdio.h>\n\nint main(void) {\n int i;\n for (i = 10; i >= 1; i--) {\n printf(\"%d\\n\", i);\n }\n return 0;\n}\n...
beam-free
qa-v1
train
118
9a9709c43ec1bd36
en
code_c
can you make a c program that reads two numbers and prints their sum pls
This program reads two integers and prints their sum. ```c #include <stdio.h> int main(void) { int a, b; printf("Enter two numbers: "); if (scanf("%d %d", &a, &b) != 2) { printf("Invalid input.\n"); return 0; } printf("Sum: %d\n", a + b); return 0; } ``` Run it and enter two num...
[ { "role": "user", "content": "can you make a c program that reads two numbers and prints their sum pls" }, { "role": "assistant", "content": "This program reads two integers and prints their sum.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a, b;\n printf(\"Enter two numbers: \");\n...
beam-free
qa-v1
train
156
754eef1552db2d22
en
code_c
celsius to fahrenheit table in c
This program prints a Celsius to Fahrenheit table from 0 to 100. ```c #include <stdio.h> int main(void) { printf("C\tF\n"); for (int c = 0; c <= 100; c += 10) { double f = c * 9.0 / 5.0 + 32.0; printf("%d\t%.1f\n", c, f); } return 0; } ``` Run it to see each Celsius value with its Fahre...
[ { "role": "user", "content": "celsius to fahrenheit table in c" }, { "role": "assistant", "content": "This program prints a Celsius to Fahrenheit table from 0 to 100.\n```c\n#include <stdio.h>\n\nint main(void) {\n printf(\"C\\tF\\n\");\n for (int c = 0; c <= 100; c += 10) {\n doubl...
beam-free
qa-v1
train
148
ddf035e4b2731d46
en
code_c
leap year check in c
This program reads a year and says whether it is a leap year. ```c #include <stdio.h> int main(void) { int year; if (scanf("%d", &year) != 1) return 0; int leap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); printf(leap ? "leap year\n" : "not a leap year\n"); return 0; } ``` Compile and...
[ { "role": "user", "content": "leap year check in c" }, { "role": "assistant", "content": "This program reads a year and says whether it is a leap year.\n```c\n#include <stdio.h>\n\nint main(void) {\n int year;\n if (scanf(\"%d\", &year) != 1) return 0;\n int leap = (year % 4 == 0 && yea...
beam-free
qa-v1
train
161
c1a4dbd128a3c8b6
en
code_c
can u write a C program to check if a year is a leap year
This program reads a year and says whether it is a leap year. ```c #include <stdio.h> int main(void) { int year; printf("Enter a year: "); if (scanf("%d", &year) != 1) { return 1; } if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { printf("%d is a leap year.\n", year);...
[ { "role": "user", "content": "can u write a C program to check if a year is a leap year" }, { "role": "assistant", "content": "This program reads a year and says whether it is a leap year.\n\n```c\n#include <stdio.h>\n\nint main(void) {\n int year;\n\n printf(\"Enter a year: \");\n if (...
beam-free
qa-v1
train
206
e218bb6966522362
en
code_c
make a power function in c using a loop
This program uses a loop to raise one integer to another integer power. ```c #include <stdio.h> int power(int base, int exp) { int result = 1; for (int i = 0; i < exp; i++) { result *= base; } return result; } int main(void) { int base, exp; printf("Base and exponent: "); if (scanf...
[ { "role": "user", "content": "make a power function in c using a loop" }, { "role": "assistant", "content": "This program uses a loop to raise one integer to another integer power.\n```c\n#include <stdio.h>\n\nint power(int base, int exp) {\n int result = 1;\n for (int i = 0; i < exp; i++)...
beam-free
qa-v1
train
222
8119180f45c600a2
en
code_c
check if a year is leap in C pls
This program reads a year and says whether it is a leap year. ```c #include <stdio.h> int main(void) { int year; printf("Enter a year: "); if (scanf("%d", &year) != 1) { return 0; } if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { printf("%d is a leap year.\n", year); ...
[ { "role": "user", "content": "check if a year is leap in C pls" }, { "role": "assistant", "content": "This program reads a year and says whether it is a leap year.\n```c\n#include <stdio.h>\n\nint main(void) {\n int year;\n\n printf(\"Enter a year: \");\n if (scanf(\"%d\", &year) != 1) ...
beam-free
qa-v1
train
199
b1fa8cefb4a6e268
en
code_c
hello world in c pls
This program prints a greeting. ```c #include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; } ``` Compile and run it; it prints Hello, world!.
[ { "role": "user", "content": "hello world in c pls" }, { "role": "assistant", "content": "This program prints a greeting.\n```c\n#include <stdio.h>\n\nint main(void) {\n printf(\"Hello, world!\\n\");\n return 0;\n}\n```\nCompile and run it; it prints Hello, world!." } ]
beam-free
qa-v1
train
65
415d2841188528d5
en
code_c
gcd program in c, takes two ints
This program reads two integers and prints their greatest common divisor. ```c #include <stdio.h> int gcd(int a, int b) { if (a < 0) { a = -a; } if (b < 0) { b = -b; } while (b != 0) { int temp = b; b = a % b; a = temp; } return a; } int main(void)...
[ { "role": "user", "content": "gcd program in c, takes two ints" }, { "role": "assistant", "content": "This program reads two integers and prints their greatest common divisor.\n```c\n#include <stdio.h>\n\nint gcd(int a, int b) {\n if (a < 0) {\n a = -a;\n }\n if (b < 0) {\n ...
beam-free
qa-v1
train
216
2f333cde29d14864
en
code_c
sum and avrage of an array in c
This program adds five numbers and prints their sum and average. ```c #include <stdio.h> int main(void) { int a[] = {10, 20, 30, 40, 50}; int n = 5; int sum = 0; for (int i = 0; i < n; i++) sum += a[i]; double avg = (double)sum / n; printf("sum = %d, average = %.2f\n", sum, avg); return 0; ...
[ { "role": "user", "content": "sum and avrage of an array in c" }, { "role": "assistant", "content": "This program adds five numbers and prints their sum and average.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a[] = {10, 20, 30, 40, 50};\n int n = 5;\n int sum = 0;\n for (int...
beam-free
qa-v1
train
183
fc36f2aec5092149
en
code_c
string length without strlen in C pls
This program reads a line and counts its characters without using strlen. ```c #include <stdio.h> int main(void) { char text[100]; if (fgets(text, sizeof(text), stdin) == NULL) { return 0; } size_t length = 0; while (text[length] != '\0') { length++; } if (length > 0 && text...
[ { "role": "user", "content": "string length without strlen in C pls" }, { "role": "assistant", "content": "This program reads a line and counts its characters without using strlen.\n```c\n#include <stdio.h>\n\nint main(void) {\n char text[100];\n if (fgets(text, sizeof(text), stdin) == NUL...
beam-free
qa-v1
train
180
5140bfeec576b222
en
code_c
make me a c program that prints a multiplication table
This program reads a number and prints its multiplication table from 1 to 10. ```c #include <stdio.h> int main(void) { int n; printf("Enter a number: "); if (scanf("%d", &n) != 1) { return 1; } for (int i = 1; i <= 10; i++) { printf("%d x %d = %d\n", n, i, n * i); } retu...
[ { "role": "user", "content": "make me a c program that prints a multiplication table" }, { "role": "assistant", "content": "This program reads a number and prints its multiplication table from 1 to 10.\n\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n\n printf(\"Enter a number: \"...
beam-free
qa-v1
train
174
10fc7ba830a7d9ad
en
code_c
calculator with switch in c, reads two numbers and an operator
This program reads two numbers and an operator, then computes the result with a switch. ```c #include <stdio.h> int main(void) { double a, b; char op; printf("Enter: number operator number: "); if (scanf("%lf %c %lf", &a, &op, &b) != 3) return 0; switch (op) { case '+': printf("%.2f\n", a +...
[ { "role": "user", "content": "calculator with switch in c, reads two numbers and an operator" }, { "role": "assistant", "content": "This program reads two numbers and an operator, then computes the result with a switch.\n```c\n#include <stdio.h>\n\nint main(void) {\n double a, b;\n char op...
beam-free
qa-v1
train
277
d0960054a7b76837
en
code_c
simple menu loop in c that reads choices
This program shows a small menu and repeats until you choose exit. ```c #include <stdio.h> int main(void) { int choice; do { printf("1. Say hi\n2. Say bye\n3. Exit\nChoice: "); if (scanf("%d", &choice) != 1) return 1; if (choice == 1) { printf("Hi!\n"); } else if (ch...
[ { "role": "user", "content": "simple menu loop in c that reads choices" }, { "role": "assistant", "content": "This program shows a small menu and repeats until you choose exit.\n```c\n#include <stdio.h>\n\nint main(void) {\n int choice;\n do {\n printf(\"1. Say hi\\n2. Say bye\\n3. ...
beam-free
qa-v1
train
220
006edc7039efec23
en
code_c
write a C program with a point struct and distance between two points
This program stores two points in a struct and prints their distance. ```c #include <stdio.h> #include <math.h> struct Point { double x; double y; }; double distance(struct Point a, struct Point b) { double dx = a.x - b.x; double dy = a.y - b.y; return sqrt(dx * dx + dy * dy); } int main(void) { ...
[ { "role": "user", "content": "write a C program with a point struct and distance between two points" }, { "role": "assistant", "content": "This program stores two points in a struct and prints their distance.\n```c\n#include <stdio.h>\n#include <math.h>\n\nstruct Point {\n double x;\n doub...
beam-free
qa-v1
train
266
522cd96014c9b2d9
en
code_c
c program to check if a year is leap year
This program reads a year and says whether it is a leap year. ```c #include <stdio.h> int main(void) { int year; if (scanf("%d", &year) != 1) { printf("Invalid input.\n"); return 0; } int leap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); printf("%d is %s.\n", year, lea...
[ { "role": "user", "content": "c program to check if a year is leap year" }, { "role": "assistant", "content": "This program reads a year and says whether it is a leap year.\n\n```c\n#include <stdio.h>\nint main(void) {\n int year;\n if (scanf(\"%d\", &year) != 1) {\n printf(\"Invali...
beam-free
qa-v1
train
191
d7921c3742dd3222
en
code_c
multiplication table program c
This program prints the multiplication table from 1 to 10. ```c #include <stdio.h> int main(void) { for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { printf("%4d", i * j); } printf("\n"); } return 0; } ``` Save it as table.c, compile with gcc -std=c11 -Wall...
[ { "role": "user", "content": "multiplication table program c" }, { "role": "assistant", "content": "This program prints the multiplication table from 1 to 10.\n```c\n#include <stdio.h>\n\nint main(void) {\n for (int i = 1; i <= 10; i++) {\n for (int j = 1; j <= 10; j++) {\n ...
beam-free
qa-v1
train
163
b079ad884fb0126a
en
code_c
find smalest number in an array c
This program checks an array of integers and prints the smallest one. ```c #include <stdio.h> int main(void) { int numbers[] = {8, 3, 12, 1, 9}; size_t count = sizeof(numbers) / sizeof(numbers[0]); int smallest = numbers[0]; for (size_t i = 1; i < count; i++) { if (numbers[i] < smallest) { ...
[ { "role": "user", "content": "find smalest number in an array c" }, { "role": "assistant", "content": "This program checks an array of integers and prints the smallest one.\n\n```c\n#include <stdio.h>\n\nint main(void) {\n int numbers[] = {8, 3, 12, 1, 9};\n size_t count = sizeof(numbers) ...
beam-free
qa-v1
train
174
040d0e1641e137d4
en
code_c
write a C program that prints the elements of a 2D array
This program prints each number in a 2 by 3 array. ```c #include <stdio.h> int main(void) { int grid[2][3] = {{1, 2, 3}, {4, 5, 6}}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { printf("%d ", grid[i][j]); } printf("\n"); } return 0; } ``` Compile it ...
[ { "role": "user", "content": "write a C program that prints the elements of a 2D array" }, { "role": "assistant", "content": "This program prints each number in a 2 by 3 array.\n```c\n#include <stdio.h>\n\nint main(void) {\n int grid[2][3] = {{1, 2, 3}, {4, 5, 6}};\n\n for (int i = 0; i < ...
beam-free
qa-v1
train
173
14e371253c5b5a1f
en
code_c
chek if a numbr is prime in c
This program reads an integer and says whether it is prime. ```c #include <stdio.h> int is_prime(int n) { if (n < 2) { return 0; } for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return 0; } } return 1; } int main(void) { int n; if (scanf("%d", &n) ...
[ { "role": "user", "content": "chek if a numbr is prime in c" }, { "role": "assistant", "content": "This program reads an integer and says whether it is prime.\n```c\n#include <stdio.h>\n\nint is_prime(int n) {\n if (n < 2) {\n return 0;\n }\n for (int i = 2; i * i <= n; i++) {\n ...
beam-free
qa-v1
train
206
4d9f9e75b4729cba
en
code_c
how do i count vowels in a string in c
This program reads a line of text and counts its vowels. ```c #include <stdio.h> int main(void) { char s[256]; printf("Enter a string: "); if (fgets(s, sizeof(s), stdin) == NULL) { return 0; } int count = 0; for (size_t i = 0; s[i] != '\0'; i++) { char c = s[i]; if (c ...
[ { "role": "user", "content": "how do i count vowels in a string in c" }, { "role": "assistant", "content": "This program reads a line of text and counts its vowels.\n```c\n#include <stdio.h>\n\nint main(void) {\n char s[256];\n\n printf(\"Enter a string: \");\n if (fgets(s, sizeof(s), s...
beam-free
qa-v1
train
269
a81f45ebd580f24f
en
code_c
basic pointer example in c
This program stores a number, points to it, reads it through the pointer, then changes it. ```c #include <stdio.h> int main(void) { int x = 42; int *p = &x; printf("x = %d\n", x); printf("address of x = %p\n", (void *)p); printf("value through pointer = %d\n", *p); *p = 7; printf("x is no...
[ { "role": "user", "content": "basic pointer example in c" }, { "role": "assistant", "content": "This program stores a number, points to it, reads it through the pointer, then changes it.\n```c\n#include <stdio.h>\n\nint main(void) {\n int x = 42;\n int *p = &x;\n\n printf(\"x = %d\\n\",...
beam-free
qa-v1
train
171
803aef33c0a5dafa
en
code_c
count vowels in a string c
This program reads a line and counts the vowels a, e, i, o and u. ```c #include <stdio.h> #include <ctype.h> int main(void) { char s[200]; if (fgets(s, sizeof s, stdin) == NULL) { return 0; } int count = 0; for (int i = 0; s[i] != '\0'; i++) { char c = (char)tolower((unsigned char)...
[ { "role": "user", "content": "count vowels in a string c" }, { "role": "assistant", "content": "This program reads a line and counts the vowels a, e, i, o and u.\n```c\n#include <stdio.h>\n#include <ctype.h>\n\nint main(void) {\n char s[200];\n if (fgets(s, sizeof s, stdin) == NULL) {\n ...
beam-free
qa-v1
train
244
97da2657e51a1bb0
en
code_c
print a triangle of stars in c
This program reads a number and prints a right triangle of stars with that many rows. ```c #include <stdio.h> int main(void) { int n; int i; int j; if (scanf("%d", &n) != 1 || n < 1) { return 0; } for (i = 1; i <= n; i++) { for (j = 0; j < i; j++) { printf("*"); ...
[ { "role": "user", "content": "print a triangle of stars in c" }, { "role": "assistant", "content": "This program reads a number and prints a right triangle of stars with that many rows.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n int i;\n int j;\n\n if (scanf(\"%d\", &n)...
beam-free
qa-v1
train
172
48b2ce5e73f1a529
en
code_c
make a multiplication table program in c
This program reads a number and prints its multiplication table from 1 to 10. ```c #include <stdio.h> int main(void) { int n; int i; if (scanf("%d", &n) != 1) { return 0; } for (i = 1; i <= 10; i++) { printf("%d x %d = %d\n", n, i, n * i); } return 0; } ``` Run it and ente...
[ { "role": "user", "content": "make a multiplication table program in c" }, { "role": "assistant", "content": "This program reads a number and prints its multiplication table from 1 to 10.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n int i;\n\n if (scanf(\"%d\", &n) != 1) {\n...
beam-free
qa-v1
train
158
268e53fc80a61eba
en
code_c
gcd in c pls
This program reads two integers and prints their greatest common divisor. ```c #include <stdio.h> int main(void) { int a, b; if (scanf("%d %d", &a, &b) != 2) { return 1; } if (a < 0) a = -a; if (b < 0) b = -b; while (b != 0) { int t = b; b = a % b; a = t; ...
[ { "role": "user", "content": "gcd in c pls" }, { "role": "assistant", "content": "This program reads two integers and prints their greatest common divisor.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a, b;\n\n if (scanf(\"%d %d\", &a, &b) != 2) {\n return 1;\n }\n\n if...
beam-free
qa-v1
train
186
0de6eece012e12cd
en
code_c
can u make a c program to bubble sort an array pls
This program sorts a small array with bubble sort. ```c #include <stdio.h> int main(void) { int a[] = {5, 2, 8, 1, 9}; int n = 5; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1 - i; j++) { if (a[j] > a[j + 1]) { int t = a[j]; a[j] = a[j + 1]...
[ { "role": "user", "content": "can u make a c program to bubble sort an array pls" }, { "role": "assistant", "content": "This program sorts a small array with bubble sort.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a[] = {5, 2, 8, 1, 9};\n int n = 5;\n\n for (int i = 0; i < n - ...
beam-free
qa-v1
train
259
8aacaee537378ccc
en
code_c
check if a word is palindrome C
This program reads one word and says whether it is a palindrome. ```c #include <stdio.h> #include <string.h> int main(void) { char word[100]; size_t len, i; int is_pal = 1; if (scanf("%99s", word) != 1) { return 1; } len = strlen(word); for (i = 0; i < len / 2; i++) { if (...
[ { "role": "user", "content": "check if a word is palindrome C" }, { "role": "assistant", "content": "This program reads one word and says whether it is a palindrome.\n```c\n#include <stdio.h>\n#include <string.h>\n\nint main(void) {\n char word[100];\n size_t len, i;\n int is_pal = 1;\n...
beam-free
qa-v1
train
234
e12d47f1b3207383
en
code_c
write a c program that prints hello world
This program prints Hello, world!. ```c #include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; } ``` Compile it with gcc and run the executable; it prints Hello, world!.
[ { "role": "user", "content": "write a c program that prints hello world" }, { "role": "assistant", "content": "This program prints Hello, world!.\n```c\n#include <stdio.h>\n\nint main(void) {\n printf(\"Hello, world!\\n\");\n return 0;\n}\n```\nCompile it with gcc and run the executable; i...
beam-free
qa-v1
train
75
aa82aafe2cc555e4
en
code_c
C program to check if a number is prime
This program reads a number and says whether it is prime. ```c #include <stdio.h> int main(void) { int n; int prime = 1; int i; printf("Enter a number: "); if (scanf("%d", &n) != 1) { return 0; } if (n <= 1) { printf("%d is not prime.\n", n); return 0; } f...
[ { "role": "user", "content": "C program to check if a number is prime" }, { "role": "assistant", "content": "This program reads a number and says whether it is prime.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n int prime = 1;\n int i;\n\n printf(\"Enter a number: \");\n ...
beam-free
qa-v1
train
251
9c4fdad7ba4c4bf5
en
code_c
hey make a c program that finds largest number in an array
This program finds the largest number in a fixed array. ```c #include <stdio.h> int main(void) { int nums[] = {12, 45, 7, 89, 23}; int n = 5; int largest = nums[0]; for (int i = 1; i < n; i++) { if (nums[i] > largest) { largest = nums[i]; } } printf("Largest number: ...
[ { "role": "user", "content": "hey make a c program that finds largest number in an array" }, { "role": "assistant", "content": "This program finds the largest number in a fixed array.\n```c\n#include <stdio.h>\n\nint main(void) {\n int nums[] = {12, 45, 7, 89, 23};\n int n = 5;\n int la...
beam-free
qa-v1
train
172
2621671c22bff447
en
code_c
can you make a C program with an array of name strings and print them
This program stores three names in an array of strings and prints them. ```c #include <stdio.h> int main(void) { const char *names[] = {"Alice", "Bob", "Charlie"}; size_t count = sizeof(names) / sizeof(names[0]); for (size_t i = 0; i < count; i++) { printf("%s\n", names[i]); } return 0; } `...
[ { "role": "user", "content": "can you make a C program with an array of name strings and print them" }, { "role": "assistant", "content": "This program stores three names in an array of strings and prints them.\n```c\n#include <stdio.h>\n\nint main(void) {\n const char *names[] = {\"Alice\", ...
beam-free
qa-v1
train
152
b2121f3d0d38d6de
en
code_c
check if a year is leap year in c
This program reads a year and says whether it is a leap year. ```c #include <stdio.h> int main(void) { int year; printf("Enter a year: "); if (scanf("%d", &year) != 1) { printf("Invalid year.\n"); return 0; } if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { print...
[ { "role": "user", "content": "check if a year is leap year in c" }, { "role": "assistant", "content": "This program reads a year and says whether it is a leap year.\n```c\n#include <stdio.h>\n\nint main(void) {\n int year;\n printf(\"Enter a year: \");\n if (scanf(\"%d\", &year) != 1) {...
beam-free
qa-v1
train
234
58c377c9d0ef6b3d
en
code_c
find the smallest number in an array c
This program reads a count and some integers, then prints the smallest. ```c #include <stdio.h> int main(void) { int count; if (scanf("%d", &count) != 1 || count <= 0) { return 0; } int values[100]; for (int i = 0; i < count; i++) { if (scanf("%d", &values[i]) != 1) { ...
[ { "role": "user", "content": "find the smallest number in an array c" }, { "role": "assistant", "content": "This program reads a count and some integers, then prints the smallest.\n```c\n#include <stdio.h>\n\nint main(void) {\n int count;\n\n if (scanf(\"%d\", &count) != 1 || count <= 0) {...
beam-free
qa-v1
train
250
ba3a0d26ec7c880a
en
code_c
make a C program that coutns from 10 down to 1
This program prints the numbers from 10 down to 1. ```c #include <stdio.h> int main(void) { for (int i = 10; i >= 1; i--) { printf("%d\n", i); } return 0; } ``` Compile and run it. It prints 10, 9, 8, 7, 6, 5, 4, 3, 2 and 1.
[ { "role": "user", "content": "make a C program that coutns from 10 down to 1" }, { "role": "assistant", "content": "This program prints the numbers from 10 down to 1.\n```c\n#include <stdio.h>\n\nint main(void) {\n for (int i = 10; i >= 1; i--) {\n printf(\"%d\\n\", i);\n }\n\n r...
beam-free
qa-v1
train
131
79b40e5e7374cd4e
en
code_c
count vowels in a string, c program
This program reads a string and counts its vowels, ignoring case. ```c #include <stdio.h> int main(void) { char text[100]; int vowels = 0; printf("Enter a string: "); if (fgets(text, sizeof(text), stdin) == NULL) { return 1; } for (int i = 0; text[i] != '\0'; i++) { char c = t...
[ { "role": "user", "content": "count vowels in a string, c program" }, { "role": "assistant", "content": "This program reads a string and counts its vowels, ignoring case.\n```c\n#include <stdio.h>\n\nint main(void) {\n char text[100];\n int vowels = 0;\n\n printf(\"Enter a string: \");\...
beam-free
qa-v1
train
279
c0788b5f5d1886f2
en
code_c
write a C program that checks if a word is a palindrome
This program reads a word and says whether it is a palindrome. ```c #include <stdio.h> #include <string.h> int main(void) { char word[64]; printf("Enter a word: "); if (scanf("%63s", word) != 1) { return 0; } size_t len = strlen(word); int palindrome = 1; for (size_t i = 0; i < le...
[ { "role": "user", "content": "write a C program that checks if a word is a palindrome" }, { "role": "assistant", "content": "This program reads a word and says whether it is a palindrome.\n```c\n#include <stdio.h>\n#include <string.h>\n\nint main(void) {\n char word[64];\n\n printf(\"Enter...
beam-free
qa-v1
train
265
dfd26939b2e3c5b0
en
code_c
string length without strlen in C
This program reads a word and counts its characters without using strlen. ```c #include <stdio.h> int main(void) { char text[100]; size_t length = 0; printf("Enter a word: "); if (fgets(text, sizeof(text), stdin) == NULL) { return 0; } while (text[length] != '\0') { length++; ...
[ { "role": "user", "content": "string length without strlen in C" }, { "role": "assistant", "content": "This program reads a word and counts its characters without using strlen.\n```c\n#include <stdio.h>\n\nint main(void) {\n char text[100];\n size_t length = 0;\n\n printf(\"Enter a word...
beam-free
qa-v1
train
193
94faebd95b03861d
en
code_c
read two numbers and print their sum in c
This program reads two integers and prints their sum. ```c #include <stdio.h> int main(void) { int a, b; printf("Enter two numbers: "); if (scanf("%d %d", &a, &b) == 2) { printf("Sum: %d\n", a + b); } else { printf("Need two numbers\n"); } return 0; } ``` Run it with 4 7; it pri...
[ { "role": "user", "content": "read two numbers and print their sum in c" }, { "role": "assistant", "content": "This program reads two integers and prints their sum.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a, b;\n printf(\"Enter two numbers: \");\n if (scanf(\"%d %d\", &a, &b...
beam-free
qa-v1
train
141
1483599ec9d41545
en
code_c
write a c program that prints a triangle of stars
This program prints a five-row triangle of stars. ```c #include <stdio.h> int main(void) { // print five rows for (int i = 1; i <= 5; i++) { for (int j = 0; j < i; j++) { putchar('*'); } putchar('\n'); } return 0; } ``` Compile it with gcc and run it; it prints rows ...
[ { "role": "user", "content": "write a c program that prints a triangle of stars" }, { "role": "assistant", "content": "This program prints a five-row triangle of stars.\n```c\n#include <stdio.h>\n\nint main(void) {\n // print five rows\n for (int i = 1; i <= 5; i++) {\n for (int j =...
beam-free
qa-v1
train
136
e8d57391269f6f6c
en
code_c
c program count from 10 down to 1
This program counts from 10 down to 1. ```c #include <stdio.h> int main(void) { for (int i = 10; i >= 1; i--) { printf("%d\n", i); } return 0; } ``` Run it; it prints 10 through 1, one number per line.
[ { "role": "user", "content": "c program count from 10 down to 1" }, { "role": "assistant", "content": "This program counts from 10 down to 1.\n```c\n#include <stdio.h>\n\nint main(void) {\n for (int i = 10; i >= 1; i--) {\n printf(\"%d\\n\", i);\n }\n\n return 0;\n}\n```\nRun it;...
beam-free
qa-v1
train
103
49bbba1b2576cd70
en
code_c
can you make a c program to find the average of numbers entered by the user
This program asks for a count, reads that many numbers, and prints their average. ```c #include <stdio.h> int main(void) { int count; printf("How many numbers? "); if (scanf("%d", &count) != 1 || count <= 0) { return 0; } double sum = 0.0; for (int i = 0; i < count; i++) { dou...
[ { "role": "user", "content": "can you make a c program to find the average of numbers entered by the user" }, { "role": "assistant", "content": "This program asks for a count, reads that many numbers, and prints their average.\n```c\n#include <stdio.h>\n\nint main(void) {\n int count;\n\n ...
beam-free
qa-v1
train
232
770dd0cd6d4eaf2b
en
code_c
make a c program for sum and average of an array
This program computes the sum and average of a fixed array. ```c #include <stdio.h> int main(void) { int arr[] = {10, 20, 30, 40, 50}; int n = 5; int sum = 0; for (int i = 0; i < n; i++) { sum += arr[i]; } printf("Sum: %d, Average: %.2f\n", sum, (double)sum / n); return 0; } ``` Com...
[ { "role": "user", "content": "make a c program for sum and average of an array" }, { "role": "assistant", "content": "This program computes the sum and average of a fixed array.\n```c\n#include <stdio.h>\n\nint main(void) {\n int arr[] = {10, 20, 30, 40, 50};\n int n = 5;\n int sum = 0;...
beam-free
qa-v1
train
180
34cded61682a86a9
en
code_c
can u make a multiplication table in C pls
This program reads a number and prints its multiplication table from 1 to 10. ```c #include <stdio.h> int main(void) { int n, i; if (scanf("%d", &n) != 1) { return 1; } for (i = 1; i <= 10; i++) { printf("%d x %d = %d\n", n, i, n * i); } return 0; } ``` Compile and run it, th...
[ { "role": "user", "content": "can u make a multiplication table in C pls" }, { "role": "assistant", "content": "This program reads a number and prints its multiplication table from 1 to 10.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n, i;\n\n if (scanf(\"%d\", &n) != 1) {\n ...
beam-free
qa-v1
train
170
c144c10ecb63a0d7
en
code_c
power function with a loop in c, reads base and exponent
This program reads a base and exponent, then computes the power with a loop. ```c #include <stdio.h> double power(double base, int exp) { double result = 1.0; for (int i = 0; i < exp; i++) { result *= base; } return result; } int main(void) { double base; int exp; printf("Enter ...
[ { "role": "user", "content": "power function with a loop in c, reads base and exponent" }, { "role": "assistant", "content": "This program reads a base and exponent, then computes the power with a loop.\n```c\n#include <stdio.h>\n\ndouble power(double base, int exp) {\n double result = 1.0;\n...
beam-free
qa-v1
train
255
4cafaa28cf8e4649
en
code_c
basic pointer example in c pls
This program stores a number, points to it, and prints both values. ```c #include <stdio.h> int main(void) { int n = 42; int *p = &n; printf("value: %d\n", n); printf("address: %p\n", (void *)p); printf("value through pointer: %d\n", *p); return 0; } ``` Save it as pointer.c, compile with gcc ...
[ { "role": "user", "content": "basic pointer example in c pls" }, { "role": "assistant", "content": "This program stores a number, points to it, and prints both values.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n = 42;\n int *p = &n;\n\n printf(\"value: %d\\n\", n);\n printf...
beam-free
qa-v1
train
166
1bf3c7b16cd28b69
en
code_c
multiplication table in c pls
This program reads a number and prints its multiplication table from 1 to 10. ```c #include <stdio.h> int main(void) { int n; printf("Number: "); if (scanf("%d", &n) != 1) { printf("Bad input.\n"); return 0; } for (int i = 1; i <= 10; i++) { printf("%d x %d = %d\n", n, i, ...
[ { "role": "user", "content": "multiplication table in c pls" }, { "role": "assistant", "content": "This program reads a number and prints its multiplication table from 1 to 10.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n\n printf(\"Number: \");\n if (scanf(\"%d\", &n) != 1)...
beam-free
qa-v1
train
189
ac5b2708a90942d1
en
code_c
c code to print ascii value of a char
This program reads one character and prints its ASCII code. ```c #include <stdio.h> int main(void) { char ch; printf("Enter a character: "); scanf(" %c", &ch); printf("ASCII code: %d\n", (unsigned char)ch); return 0; } ``` Compile it with gcc -std=c11 -Wall -Wextra and run it. With input A it print...
[ { "role": "user", "content": "c code to print ascii value of a char" }, { "role": "assistant", "content": "This program reads one character and prints its ASCII code.\n```c\n#include <stdio.h>\n\nint main(void) {\n char ch;\n printf(\"Enter a character: \");\n scanf(\" %c\", &ch);\n ...
beam-free
qa-v1
train
129
eb19099ddee66683
en
code_c
copy string without strcpy c
This program copies one string into another by hand. ```c #include <stdio.h> int main(void) { char src[] = "Hello"; char dst[100]; int i = 0; while (src[i] != '\0') { dst[i] = src[i]; i++; } dst[i] = '\0'; printf("Copied: %s\n", dst); return 0; } ``` It prints Copied: He...
[ { "role": "user", "content": "copy string without strcpy c" }, { "role": "assistant", "content": "This program copies one string into another by hand.\n```c\n#include <stdio.h>\n\nint main(void) {\n char src[] = \"Hello\";\n char dst[100];\n int i = 0;\n while (src[i] != '\\0') {\n ...
beam-free
qa-v1
train
142
5976269bae553d3d
en
code_c
print elements of a 2D array in C
This program stores a 2 by 3 array and prints all of its elements. ```c #include <stdio.h> int main(void) { int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; int i, j; for (i = 0; i < 2; i++) { for (j = 0; j < 3; j++) { printf("%d ", a[i][j]); } printf("\n"); } return 0; }...
[ { "role": "user", "content": "print elements of a 2D array in C" }, { "role": "assistant", "content": "This program stores a 2 by 3 array and prints all of its elements.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a[2][3] = {{1, 2, 3}, {4, 5, 6}};\n int i, j;\n\n for (i = 0; i <...
beam-free
qa-v1
train
175
ffa3bcbf6a95b8b0
en
code_c
how do i print a 2d array in c
This program prints the elements of a fixed 3 by 3 array. ```c #include <stdio.h> int main(void) { int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) printf("%d ", a[i][j]); printf("\n"); } return 0; } ``` Compile it wi...
[ { "role": "user", "content": "how do i print a 2d array in c" }, { "role": "assistant", "content": "This program prints the elements of a fixed 3 by 3 array.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};\n for (int i = 0; i < 3; i++) {\n ...
beam-free
qa-v1
train
181
194f2e18c22cf0e7
en
code_c
write a C program that counts the vowels in a string
This program reads a line from input and counts the vowels in it. ```c #include <stdio.h> #include <ctype.h> int main(void) { char s[200]; printf("Enter a string: "); if (fgets(s, sizeof s, stdin) == NULL) return 0; int count = 0; for (int i = 0; s[i] != '\0'; i++) { char c = tolower((unsig...
[ { "role": "user", "content": "write a C program that counts the vowels in a string" }, { "role": "assistant", "content": "This program reads a line from input and counts the vowels in it.\n```c\n#include <stdio.h>\n#include <ctype.h>\n\nint main(void) {\n char s[200];\n printf(\"Enter a st...
beam-free
qa-v1
train
254
f3b9347aca86ffa3
en
code_c
check if a number is prime, C program
This program reads an integer and says whether it is prime. ```c #include <stdio.h> int main(void) { int n; if (scanf("%d", &n) != 1) { return 0; } if (n < 2) { printf("%d is not prime\n", n); return 0; } int prime = 1; for (int i = 2; i <= n / i; i++) { if (...
[ { "role": "user", "content": "check if a number is prime, C program" }, { "role": "assistant", "content": "This program reads an integer and says whether it is prime.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n if (scanf(\"%d\", &n) != 1) {\n return 0;\n }\n if (n...
beam-free
qa-v1
train
229
ebe8671f767a5aa3
en
code_c
check if a word is palindrome c program
This program checks whether a word reads the same forwards and backwards. ```c #include <stdio.h> #include <string.h> int is_palindrome(const char *s) { size_t len = strlen(s); for (size_t i = 0; i < len / 2; i++) { if (s[i] != s[len - 1 - i]) { return 0; } } return 1; } in...
[ { "role": "user", "content": "check if a word is palindrome c program" }, { "role": "assistant", "content": "This program checks whether a word reads the same forwards and backwards.\n```c\n#include <stdio.h>\n#include <string.h>\n\nint is_palindrome(const char *s) {\n size_t len = strlen(s);...
beam-free
qa-v1
train
224
7f8e5dc340a2c031
en
code_c
C program to print a number in binary
This program prints a non-negative number in binary. ```c #include <stdio.h> int main(void) { unsigned int n; if (scanf("%u", &n) != 1) return 0; int started = 0; for (int i = 31; i >= 0; i--) { if (n & (1u << i)) { putchar('1'); started = 1; } else if (started) ...
[ { "role": "user", "content": "C program to print a number in binary" }, { "role": "assistant", "content": "This program prints a non-negative number in binary.\n```c\n#include <stdio.h>\n\nint main(void) {\n unsigned int n;\n if (scanf(\"%u\", &n) != 1) return 0;\n int started = 0;\n ...
beam-free
qa-v1
train
203
9f654f362c553b88
en
code_c
write c prog for sum and avg of array
This program adds the numbers in an array and prints their sum and average. ```c #include <stdio.h> int main(void) { int a[] = {4, 7, 2, 9, 5}; int n = 5; int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } printf("Sum: %d, Average: %.2f\n", sum, (double)sum / n); return 0;...
[ { "role": "user", "content": "write c prog for sum and avg of array" }, { "role": "assistant", "content": "This program adds the numbers in an array and prints their sum and average.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a[] = {4, 7, 2, 9, 5};\n int n = 5;\n int sum = 0;\n...
beam-free
qa-v1
train
169
15c7abb0d9ab421b
en
code_c
print elements of a 2d array c
This program fills a 2 by 3 array and prints every element. ```c #include <stdio.h> int main(void) { int grid[2][3] = {{1, 2, 3}, {4, 5, 6}}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { printf("%d ", grid[i][j]); } printf("\n"); } return 0; } ``` Comp...
[ { "role": "user", "content": "print elements of a 2d array c" }, { "role": "assistant", "content": "This program fills a 2 by 3 array and prints every element.\n```c\n#include <stdio.h>\n\nint main(void) {\n int grid[2][3] = {{1, 2, 3}, {4, 5, 6}};\n for (int i = 0; i < 2; i++) {\n ...
beam-free
qa-v1
train
165
94f95e2e844439a2
en
code_c
can you make a power function in C using a loop
This program raises a base to a non-negative exponent using a loop. ```c #include <stdio.h> double power(double base, int exp) { double result = 1.0; for (int i = 0; i < exp; i++) { result *= base; } return result; } int main(void) { double base; int exp; if (scanf("%lf %d", &base,...
[ { "role": "user", "content": "can you make a power function in C using a loop" }, { "role": "assistant", "content": "This program raises a base to a non-negative exponent using a loop.\n```c\n#include <stdio.h>\n\ndouble power(double base, int exp) {\n double result = 1.0;\n for (int i = 0...
beam-free
qa-v1
train
214
362e9e5e4eabce25
en
code_c
reverse a string in c please
This program reads a line, reverses it in place, and prints it. ```c #include <stdio.h> #include <string.h> int main(void) { char s[100]; if (fgets(s, sizeof s, stdin) == NULL) { return 1; } size_t len = strlen(s); if (len > 0 && s[len - 1] == '\n') { s[len - 1] = '\0'; len-...
[ { "role": "user", "content": "reverse a string in c please" }, { "role": "assistant", "content": "This program reads a line, reverses it in place, and prints it.\n```c\n#include <stdio.h>\n#include <string.h>\n\nint main(void) {\n char s[100];\n if (fgets(s, sizeof s, stdin) == NULL) {\n ...
beam-free
qa-v1
train
249
fbc59bdafe51cd8f
en
code_c
multiplication table in c
This program reads a size and prints a multiplication table up to that size. ```c #include <stdio.h> int main(void) { int n; if (scanf("%d", &n) != 1 || n < 1 || n > 12) { return 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { printf("%4d", i * j); ...
[ { "role": "user", "content": "multiplication table in c" }, { "role": "assistant", "content": "This program reads a size and prints a multiplication table up to that size.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n if (scanf(\"%d\", &n) != 1 || n < 1 || n > 12) {\n ret...
beam-free
qa-v1
train
189
89a3567f833c15fd
en
code_c
can you reverse an array in C?
This program reads some numbers, reverses them in place, and prints them. ```c #include <stdio.h> int main(void) { int a[100]; int n; printf("How many numbers? "); if (scanf("%d", &n) != 1 || n < 1 || n > 100) { printf("Bad input.\n"); return 0; } for (int i = 0; i < n; i++) {...
[ { "role": "user", "content": "can you reverse an array in C?" }, { "role": "assistant", "content": "This program reads some numbers, reverses them in place, and prints them.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a[100];\n int n;\n\n printf(\"How many numbers? \");\n if ...
beam-free
qa-v1
train
325
c9279b8c7d67a026
en
code_c
read two numbers and print thier sum in c
This program reads two integers and prints their sum. ```c #include <stdio.h> int main(void) { int a, b; if (scanf("%d %d", &a, &b) != 2) return 1; printf("Sum: %d\n", a + b); return 0; } ``` Compile with gcc and run it, then type two numbers separated by a space. It prints their sum, like "Sum: 7" for...
[ { "role": "user", "content": "read two numbers and print thier sum in c" }, { "role": "assistant", "content": "This program reads two integers and prints their sum.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a, b;\n if (scanf(\"%d %d\", &a, &b) != 2) return 1;\n printf(\"Sum: %...
beam-free
qa-v1
train
135
0e85d4e722ed1312
en
code_c
chek if a number is even or odd c
This program reads a number and says whether it is even or odd. ```c #include <stdio.h> int main(void) { int number; if (scanf("%d", &number) != 1) { printf("enter an integer\n"); return 0; } if (number % 2 == 0) { printf("%d is even\n", number); } else { printf("%...
[ { "role": "user", "content": "chek if a number is even or odd c" }, { "role": "assistant", "content": "This program reads a number and says whether it is even or odd.\n```c\n#include <stdio.h>\n\nint main(void) {\n int number;\n\n if (scanf(\"%d\", &number) != 1) {\n printf(\"enter ...
beam-free
qa-v1
train
163
95b93b8ec8588c81
en
code_c
greatest common divisor in c
This program reads two numbers and prints their greatest common divisor. ```c #include <stdio.h> int main(void) { int a; int b; int t; printf("Enter two numbers: "); if (scanf("%d %d", &a, &b) != 2) { return 0; } if (a < 0) { a = -a; } if (b < 0) { b = -b; ...
[ { "role": "user", "content": "greatest common divisor in c" }, { "role": "assistant", "content": "This program reads two numbers and prints their greatest common divisor.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a;\n int b;\n int t;\n\n printf(\"Enter two numbers: \");\n ...
beam-free
qa-v1
train
235
dab991b307b95f0a
en
code_c
reverse a string in c
This program reads a line of text and prints it reversed. ```c #include <stdio.h> #include <string.h> int main(void) { char str[100]; if (fgets(str, sizeof(str), stdin) == NULL) { return 0; } size_t len = strlen(str); if (len > 0 && str[len - 1] == '\n') { str[--len] = '\0'; }...
[ { "role": "user", "content": "reverse a string in c" }, { "role": "assistant", "content": "This program reads a line of text and prints it reversed.\n```c\n#include <stdio.h>\n#include <string.h>\n\nint main(void) {\n char str[100];\n\n if (fgets(str, sizeof(str), stdin) == NULL) {\n ...
beam-free
qa-v1
train
236
98920292c23bfeda
en
code_c
hey can u write c code that says if a number is even or odd
This program reads one number and says whether it is even or odd. ```c #include <stdio.h> int main(void) { int n; printf("Enter a number: "); if (scanf("%d", &n) == 1) { if (n % 2 == 0) { printf("%d is even\n", n); } else { printf("%d is odd\n", n); } } e...
[ { "role": "user", "content": "hey can u write c code that says if a number is even or odd" }, { "role": "assistant", "content": "This program reads one number and says whether it is even or odd.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n printf(\"Enter a number: \");\n if ...
beam-free
qa-v1
train
172
04c6f2186a97df47
en
code_c
copy a string into another in c without strcpy
This program copies one string into another character by character. ```c #include <stdio.h> int main(void) { char source[] = "hello"; char dest[20]; int i = 0; while (source[i] != '\0') { dest[i] = source[i]; i++; } dest[i] = '\0'; printf("copied string: %s\n", dest); ...
[ { "role": "user", "content": "copy a string into another in c without strcpy" }, { "role": "assistant", "content": "This program copies one string into another character by character.\n```c\n#include <stdio.h>\n\nint main(void) {\n char source[] = \"hello\";\n char dest[20];\n int i = 0...
beam-free
qa-v1
train
152
6b0604156a07750e
en
code_c
write a C program that sums the digits of a number pls
This program reads an integer and prints the sum of its digits. ```c #include <stdio.h> int main(void) { int n, sum = 0; printf("Enter a number: "); scanf("%d", &n); if (n < 0) n = -n; while (n > 0) { sum += n % 10; n /= 10; } printf("Sum of digits: %d\n", sum); return 0...
[ { "role": "user", "content": "write a C program that sums the digits of a number pls" }, { "role": "assistant", "content": "This program reads an integer and prints the sum of its digits.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n, sum = 0;\n printf(\"Enter a number: \");\n s...
beam-free
qa-v1
train
184
179300bf9363155d
en
code_c
c program to check even or odd number, quick pls
This program reads one integer and says whether it is even or odd. ```c #include <stdio.h> int main(void) { int n; printf("Enter a number: "); if (scanf("%d", &n) != 1) { printf("Invalid input.\n"); return 0; } if (n % 2 == 0) { printf("%d is even.\n", n); } else { ...
[ { "role": "user", "content": "c program to check even or odd number, quick pls" }, { "role": "assistant", "content": "This program reads one integer and says whether it is even or odd.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n printf(\"Enter a number: \");\n if (scanf(\"%...
beam-free
qa-v1
train
175
580fe4fa91d63a07
en
code_c
write a C program that uses a pointer to print a value
This program stores a value and prints it through a pointer. ```c #include <stdio.h> int main(void) { int x = 42; int *p = &x; printf("value: %d\n", *p); return 0; } ``` Compile it with gcc -Wall -Wextra and run it; it prints value: 42.
[ { "role": "user", "content": "write a C program that uses a pointer to print a value" }, { "role": "assistant", "content": "This program stores a value and prints it through a pointer.\n```c\n#include <stdio.h>\n\nint main(void) {\n int x = 42;\n int *p = &x;\n printf(\"value: %d\\n\", ...
beam-free
qa-v1
train
109
00367f6aba8b935d
en
code_c
sum of the digits of a number in c pls
This program reads an integer and prints the sum of its digits. ```c #include <stdio.h> int main(void) { int n; if (scanf("%d", &n) != 1) { return 1; } int sum = 0; int x = n < 0 ? -n : n; while (x > 0) { sum += x % 10; x /= 10; } printf("digit sum of %d is %...
[ { "role": "user", "content": "sum of the digits of a number in c pls" }, { "role": "assistant", "content": "This program reads an integer and prints the sum of its digits.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n\n if (scanf(\"%d\", &n) != 1) {\n return 1;\n }\n\n...
beam-free
qa-v1
train
193
605aed4bfe550a1a
en
code_c
avrage of numbers entered by the user in C
This program reads a count and some numbers, then prints their average. ```c #include <stdio.h> int main(void) { int count; if (scanf("%d", &count) != 1 || count <= 0) return 0; double sum = 0.0; for (int i = 0; i < count; i++) { double value; if (scanf("%lf", &value) != 1) return 0; ...
[ { "role": "user", "content": "avrage of numbers entered by the user in C" }, { "role": "assistant", "content": "This program reads a count and some numbers, then prints their average.\n```c\n#include <stdio.h>\n\nint main(void) {\n int count;\n if (scanf(\"%d\", &count) != 1 || count <= 0)...
beam-free
qa-v1
train
197
56f7d2119573b98d
en
code_c
find the smallest number in an array in C
This program stores a small array and prints its smallest value. ```c #include <stdio.h> int main(void) { int a[] = { 5, 2, 9, 1, 7 }; int n = sizeof a / sizeof a[0]; int min = a[0]; for (int i = 1; i < n; i++) if (a[i] < min) min = a[i]; printf("Smallest: %d\n", min); return 0; } ``` Compile a...
[ { "role": "user", "content": "find the smallest number in an array in C" }, { "role": "assistant", "content": "This program stores a small array and prints its smallest value.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a[] = { 5, 2, 9, 1, 7 };\n int n = sizeof a / sizeof a[0];\n ...
beam-free
qa-v1
train
162
eac1928f9235cc5a
en
code_c
average of numbers entered by user in c, thanks
This program reads how many numbers you want, then their values, and prints their average. ```c #include <stdio.h> int main(void) { int n; printf("How many numbers? "); if (scanf("%d", &n) != 1 || n <= 0) { printf("Please enter a positive count.\n"); return 0; } double sum = 0.0; ...
[ { "role": "user", "content": "average of numbers entered by user in c, thanks" }, { "role": "assistant", "content": "This program reads how many numbers you want, then their values, and prints their average.\n```c\n#include <stdio.h>\n\nint main(void) {\n int n;\n printf(\"How many numbers...
beam-free
qa-v1
train
271
4e16db67d69751fd
en
code_c
sum the digits of a number in C
This program reads an integer and prints the sum of its digits. ```c #include <stdio.h> int main(void) { long n; if (scanf("%ld", &n) != 1) { return 0; } if (n < 0) { n = -n; } int sum = 0; while (n > 0) { sum += (int)(n % 10); n /= 10; } printf("sum:...
[ { "role": "user", "content": "sum the digits of a number in C" }, { "role": "assistant", "content": "This program reads an integer and prints the sum of its digits.\n```c\n#include <stdio.h>\n\nint main(void) {\n long n;\n if (scanf(\"%ld\", &n) != 1) {\n return 0;\n }\n if (n...
beam-free
qa-v1
train
186
a40b99d30fbeaaa8
en
code_c
allocate an array with malloc and free it in c
This program allocates an array with malloc, fills it, prints it, and frees it. ```c #include <stdio.h> #include <stdlib.h> int main(void) { int n; if (scanf("%d", &n) != 1 || n <= 0) { return 0; } // allocate and fill the array int *a = malloc(n * sizeof *a); if (a == NULL) { p...
[ { "role": "user", "content": "allocate an array with malloc and free it in c" }, { "role": "assistant", "content": "This program allocates an array with malloc, fills it, prints it, and frees it.\n```c\n#include <stdio.h>\n#include <stdlib.h>\n\nint main(void) {\n int n;\n if (scanf(\"%d\"...
beam-free
qa-v1
train
261
02b3c9e621a2af60
en
code_c
bubble sort an array c
This program sorts a small array with bubble sort and prints it. ```c #include <stdio.h> int main(void) { int a[] = {5, 2, 9, 1, 6}; int n = 5; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1 - i; j++) { if (a[j] > a[j + 1]) { int t = a[j]; a...
[ { "role": "user", "content": "bubble sort an array c" }, { "role": "assistant", "content": "This program sorts a small array with bubble sort and prints it.\n```c\n#include <stdio.h>\n\nint main(void) {\n int a[] = {5, 2, 9, 1, 6};\n int n = 5;\n\n for (int i = 0; i < n - 1; i++) {\n ...
beam-free
qa-v1
train
291
ead6106a07d73ea6
en
code_c
celsuis to fahrenheit table in c
This program prints Celsius values from 0 to 100 with their Fahrenheit equivalents. ```c #include <stdio.h> int main(void) { for (int c = 0; c <= 100; c += 10) { printf("%d C = %.1f F\n", c, c * 9.0 / 5.0 + 32.0); } return 0; } ``` Compile and run it. It prints 11 lines from 0 C to 100 C.
[ { "role": "user", "content": "celsuis to fahrenheit table in c" }, { "role": "assistant", "content": "This program prints Celsius values from 0 to 100 with their Fahrenheit equivalents.\n```c\n#include <stdio.h>\n\nint main(void) {\n for (int c = 0; c <= 100; c += 10) {\n printf(\"%d C...
beam-free
qa-v1
train
147
26bfdea7bac1a5c4
en
code_c
fizzbuzz 1 to 30 in c plz
This program prints FizzBuzz from 1 to 30. ```c #include <stdio.h> int main(void) { for (int i = 1; i <= 30; i++) { if (i % 15 == 0) { printf("FizzBuzz\n"); } else if (i % 3 == 0) { printf("Fizz\n"); } else if (i % 5 == 0) { printf("Buzz\n"); } el...
[ { "role": "user", "content": "fizzbuzz 1 to 30 in c plz" }, { "role": "assistant", "content": "This program prints FizzBuzz from 1 to 30.\n```c\n#include <stdio.h>\n\nint main(void) {\n for (int i = 1; i <= 30; i++) {\n if (i % 15 == 0) {\n printf(\"FizzBuzz\\n\");\n ...
beam-free
qa-v1
train
215
e4775e19fa48fc1c
en
code_c
count vowels in a string in C pls
This program reads a line and counts its vowels. ```c #include <stdio.h> #include <string.h> #include <ctype.h> int main(void) { char s[256]; if (fgets(s, sizeof s, stdin) == NULL) { return 0; } int count = 0; for (size_t i = 0; s[i] != '\0'; i++) { char c = (char)tolower((unsigned ...
[ { "role": "user", "content": "count vowels in a string in C pls" }, { "role": "assistant", "content": "This program reads a line and counts its vowels.\n```c\n#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n\nint main(void) {\n char s[256];\n if (fgets(s, sizeof s, stdin) == N...
beam-free
qa-v1
train
248
d9ab438963dc7a23
en
code_c
c program to check if a charachter is a letter or digit
This program reads one character and says if it is a letter, a digit, or neither. ```c #include <stdio.h> int main(void) { char ch; printf("Enter one character: "); if (scanf(" %c", &ch) != 1) { return 0; } if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { printf("'%c' i...
[ { "role": "user", "content": "c program to check if a charachter is a letter or digit" }, { "role": "assistant", "content": "This program reads one character and says if it is a letter, a digit, or neither.\n```c\n#include <stdio.h>\n\nint main(void) {\n char ch;\n\n printf(\"Enter one cha...
beam-free
qa-v1
train
254
7f6a199eb8fa222f
en
code_c
c program to check if a word is a palindrome
This program reads one word and checks whether it reads the same backward. ```c #include <stdio.h> #include <string.h> int main(void) { char word[100]; if (scanf("%99s", word) != 1) { return 0; } int length = (int)strlen(word); int is_palindrome = 1; for (int i = 0; i < length / 2; i++...
[ { "role": "user", "content": "c program to check if a word is a palindrome" }, { "role": "assistant", "content": "This program reads one word and checks whether it reads the same backward.\n```c\n#include <stdio.h>\n#include <string.h>\n\nint main(void) {\n char word[100];\n if (scanf(\"%9...
beam-free
qa-v1
train
234
effba1d615564904
en
code_c
convert seconds into hours minutes and seconds in c
This program reads total seconds and prints hours, minutes, and seconds. ```c #include <stdio.h> int main(void) { int total; if (scanf("%d", &total) != 1 || total < 0) return 1; int h = total / 3600; int m = (total % 3600) / 60; int s = total % 60; printf("%d h %d m %d s\n", h, m, s); retur...
[ { "role": "user", "content": "convert seconds into hours minutes and seconds in c" }, { "role": "assistant", "content": "This program reads total seconds and prints hours, minutes, and seconds.\n```c\n#include <stdio.h>\n\nint main(void) {\n int total;\n if (scanf(\"%d\", &total) != 1 || t...
beam-free
qa-v1
train
183
dd59ba340fdfd35f
en
code_c
make a triangle of stars in c
This program prints a five-row triangle of stars. ```c #include <stdio.h> int main(void) { int i, j; for (i = 1; i <= 5; i++) { for (j = 0; j < i; j++) { putchar('*'); } putchar('\n'); } return 0; } ``` Compile and run it; it prints the triangle with no input.
[ { "role": "user", "content": "make a triangle of stars in c" }, { "role": "assistant", "content": "This program prints a five-row triangle of stars.\n```c\n#include <stdio.h>\nint main(void) {\n int i, j;\n for (i = 1; i <= 5; i++) {\n for (j = 0; j < i; j++) {\n putchar(...
beam-free
qa-v1
train
125