Вот код для печати «Hello, World!» в С:
Метод 1: использование printf()
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
Метод 2: использование puts()
#include <stdio.h>
int main() {
puts("Hello, World!");
return 0;
}
Метод 3: использование putchar()
#include <stdio.h>
int main() {
char hello[] = "Hello, World!";
int i = 0;
while (hello[i] != '\0') {
putchar(hello[i]);
i++;
}
return 0;
}
Метод 4: использование fprintf()
#include <stdio.h>
int main() {
FILE *file = fopen("output.txt", "w");
if (file != NULL) {
fprintf(file, "Hello, World!");
fclose(file);
}
return 0;
}
Метод 5: использование sprintf()
#include <stdio.h>
int main() {
char buffer[50];
sprintf(buffer, "Hello, World!");
printf("%s", buffer);
return 0;
}
Метод 6: использование fwrite()
#include <stdio.h>
int main() {
FILE *file = fopen("output.txt", "wb");
if (file != NULL) {
const char *hello = "Hello, World!";
fwrite(hello, sizeof(char), strlen(hello), file);
fclose(file);
}
return 0;
}