主题:麻烦各位,给我发一些经典程序,尽可能包含C语言中各章知识点。
梨花雪sts
[专家分:0] 发布于 2011-12-06 22:47:00
麻烦各位,给我发一些经典程序,尽可能包含C语言中各章知识点。邮箱:1062143940@qq.com
回复列表 (共2个回复)
沙发
gnux [专家分:0] 发布于 2011-12-13 09:51:00
以下程序是最经典的
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Hello world!\n");
return 0;
}
板凳
gan452731 [专家分:0] 发布于 2011-12-17 11:31:00
PE 2-1
/* Programming Exercise 2-1 */
#include <stdio.h>
int main(void)
{
printf("Anton Bruckner\n");
printf("Anton\nBruckner\n");
printf("Anton ");
printf("Bruckner\n");
return 0;
}
PE 2-3
/* Programming Exercise 2-3 */
#include <stdio.h>
int main(void)
{
int ageyears; /* age in years */
int agedays; /* age in days */
/* large ages may require the long type */
ageyears = 44;
agedays = 365 * ageyears;
printf("An age of %d years is %d days.\n", ageyears, agedays);
return 0;
}
PE 2-4
/* Programming Exercise 2-4 */
#include <stdio.h>
void jolly(void);
void deny(void);
int main(void)
{
jolly();
jolly();
jolly();
deny();
return 0;
}
void jolly(void)
{
printf("For he's a jolly good fellow!\n");
}
void deny(void)
{
printf("Which nobody can deny!\n");
}
PE 2-5
/* Programming Exercise 2-5 */
#include <stdio.h>
int main(void)
{
int toes;
toes = 10;
printf("toes = %d\n", toes);
printf("Twice toes = %d\n", 2 * toes);
printf("toes squared = %d\n", toes * toes);
return 0;
}
/* or create two more variables, set them to 2 * toes and toes * toes */
PE 2-7
/* Programming Exercise 2-7 */
#include <stdio.h>
void one_three(void);
void two(void);
int main(void)
{
printf("starting now:\n");
one_three();
printf("done!\n");
return 0;
}
void one_three(void)
{
printf("one\n");
two();
printf("three\n");
}
void two(void)
{
printf("two\n");
}
Chapter 3
PE 3-2
/* Programming Exercise 3-2 */
#include <stdio.h>
int main(void)
{
int ascii;
printf("Enter an ASCII code: ");
scanf("%d", &ascii);
printf("%d is the ASCII code for %c.\n", ascii, ascii);
return 0;
}
PE 3-4
/* Programming Exercise 3-4 */
#include <stdio.h>
int main(void)
{
float num;
printf("Enter a floating-point value: ");
scanf("%f", &num);
printf("fixed-point notation: %f\n", num);
printf("exponential notation: %e\n", num);
return 0;
}
我来回复