📅  最后修改于: 2023-12-03 15:14:26.539000             🧑  作者: Mango
C语言是一种功能强大的编程语言,它具有高效、灵活和可移植等特点,在计算机编程领域被广泛应用。在C语言中,输出是一个非常重要的操作,它可以在屏幕上输出数据、结果和错误信息,帮助程序员快速调试程序和查找问题。
本套装共包含29个C程序的输出实例,分别涵盖基础语法、数组、指针、函数、结构体等方面,旨在帮助程序员更好地掌握C语言的输出操作,提高编程能力和水平。
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
#include <stdio.h>
int main() {
int num = 123;
printf("The number is: %d", num);
return 0;
}
#include <stdio.h>
int main() {
float num = 3.1415926;
printf("The number is: %f", num);
return 0;
}
#include <stdio.h>
int main() {
char ch = 'A';
printf("The character is: %c", ch);
return 0;
}
#include <stdio.h>
int main() {
char str[] = "Hello World!";
printf("%s", str);
return 0;
}
#include <stdio.h>
int main() {
int arr[] = {1,2,3,4,5};
int size = sizeof(arr)/sizeof(arr[0]);
for(int i=0; i<size; i++) {
printf("%d ", arr[i]);
}
return 0;
}
#include <stdio.h>
int main() {
int arr[][3] = {{1,2,3}, {4,5,6}};
int rows = sizeof(arr)/sizeof(arr[0]);
int cols = sizeof(arr[0])/sizeof(arr[0][0]);
for(int i=0; i<rows; i++) {
for(int j=0; j<cols; j++) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
return 0;
}
#include <stdio.h>
int main() {
int num = 123;
int *p = #
printf("The address of num is: %p", p);
return 0;
}
#include <stdio.h>
int main() {
int num = 123;
int *p = #
printf("The value pointed by p is: %d", *p);
return 0;
}
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
int a = 3, b = 5;
int result = add(a, b);
printf("The result is: %d", result);
return 0;
}
#include <stdio.h>
void printNum(int num) {
printf("The number is: %d", num);
}
int main() {
int num = 123;
printNum(num);
return 0;
}
#include <stdio.h>
struct Student {
char name[20];
int age;
float score;
} stu;
int main() {
strcpy(stu.name, "John");
stu.age = 18;
stu.score = 90.5;
printf("Name: %s\nAge: %d\nScore: %.1f", stu.name, stu.age, stu.score);
return 0;
}
#include <stdio.h>
struct Student {
char name[20];
int age;
float score;
} stu, *pStu;
int main() {
strcpy(stu.name, "John");
stu.age = 18;
stu.score = 90.5;
pStu = &stu;
printf("Name: %s\nAge: %d\nScore: %.1f", pStu->name, pStu->age, pStu->score);
return 0;
}
以上是本套装的全部内容,希望对程序员们有所帮助。