#include
int main() {
int i;
char letter[26+1];
for(i = 0; i < 26; i++) {
letter[i] = i + 97;
printf("%c ", letter[i]);
}
return 0;
}
#include
int main() {
int i, j;
for(i = 0; i < 5; i++) {
for(j = 0; j <= i; j++)
printf("$");
printf("\n");
}
return 0;
}
#include
int main() {
int i, j;
for(i = 0; i < 6; i++) {
for(j = 0; j <= i; j++)
printf("%c", 'F'-j);
printf("\n");
}
// char lets[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//
// for(i = 0; i < 6; i++) {
// for(j = 0; j <= i; j++)
// printf("%c", lets[5-j]);
// printf("\n");
// }
return 0;
}
#include
int main() {
int i, j, k = 0;
for(i = 0; i < 6; i++, k+=j) {
for(j = 0; j <= i; j++)
printf("%c", 'A'+k+j);
printf("\n");
}
// char lets[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//
// for(i = 0; i < 6; i++) {
// for(j = 0; j <= i; j++)
// printf("%c", lets[k+j]);
// printf("\n");
// k += j;
// }
return 0;
}
#include
int main() {
int i, j;
char range[5];
printf("Please enter an upper letter:\n");
scanf("%c", &range[4]);
for(i = 1; i <= 4; i++) {
range[4-i] = range[4] - i;
if(range[4-i] < 65)
range[4-i] = 90;
}
for(i = 0; i < 5; i++) {
for(j = 0; j < 4-i; j++)
printf(" ");
for(j = 0; j <= i; j++)
printf("%c", range[j]);
for(j = i-1; j >= 0; j--)
printf("%c", range[j]);
printf("\n");
}
return 0;
}
#include
int main() {
int lwrLimit, uprLimit, i;
printf("Please the range of your table(in Interger):\n");
scanf("%d%d", &lwrLimit, &uprLimit);
printf("Integer\t Square\t Cube\n");
for(i = lwrLimit; i <= uprLimit; i++)
printf("%d\t %d\t %d\n", i, i*i, i*i*i);
return 0;
}
#include
#include
int main() {
int i;
char str[20];
printf("Please enter one English word:\n");
scanf("%s", str);
for(i = 0; i < strlen(str); i++)
printf("%c", str[strlen(str)-i-1]);
printf("\n");
return 0;
}
#include
int main() {
float f1, f2;
printf("Please enter two floating number:\n");
while(scanf("%f%f", &f1, &f2)) {
printf("(%.2f - %.2f) / (%.2f * %.2f) = %.2f\n",
f1, f2, f1, f2, (f1-f2)/(f1*f2));
printf("Enter next two floating number(q to quit):\n");
}
return 0;
}
#include
int main() {
float fun(float f1, float f2);
float f1, f2;
printf("Please enter two floating number:\n");
while(scanf("%f%f", &f1, &f2)) {
printf("(%.2f - %.2f) / (%.2f * %.2f) = %.2f\n",
f1, f2, f1, f2, fun(f1, f2));
printf("Enter next two floating number(q to quit):\n");
}
return 0;
}
float fun(float f1, float f2) {
return (f1-f2)/(f1*f2);
}
#include
int main() {
int lwrLimit, uprLimit, i, sum;
printf("Enter lower and upper integer limits: ");
while(scanf("%d%d", &lwrLimit, &uprLimit) && lwrLimit < uprLimit) {
sum = 0;
for(i = lwrLimit; i <= uprLimit; i++)
sum += i * i;
printf("The sums of the squares from %d to %d is %d\n",
lwrLimit*lwrLimit, uprLimit*uprLimit, sum);
printf("Enter next set of limits: ");
}
printf("Done\n");
return 0;
}
#include
int main() {
int arr[8], i;
printf("Please enter 8 Interger number:\n");
for(i = 0; i < 8; i++)
scanf("%d", &arr[i]);
for(i = 7; i >= 0; i--)
printf("%d ", arr[i]);
printf("\n");
return 0;
}
#include
int main() {
int times, i;
double s1, s2, sum1, sum2;
printf("Please enter the execution times:\n");
while(scanf("%d", ×)) {
s1 = s2 = 1.0;
sum1 = sum2 = 0.0;
for(i = 1; i <= times; i++) {
sum1 += s1;
sum2 += s2;
s1 *= 1.0 * i / (i+1);
s2 *= (-1.0) * i / (i+1);
}
printf("1.0 + 1.0/2.0 + 1.0/3.0 +... = %.5f\n", sum1);
printf("1.0 - 1.0/2.0 + 1.0/3.0 -... = %.5f\n", sum2);
printf("Enter next execution times(q to quit):\n");
}
return 0;
}
#include
int main() {
int power[8], i;
power[0] = 2;
for(i = 1; i < 8; i++)
power[i] = 2 * power[i-1];
i = 0;
do {
printf("%d ", power[i]);
i++;
}while(i < 8);
printf("\n");
return 0;
}
#include
int main() {
int i;
double arr[8], sum[8];
printf("Please enter 8 double number:\n");
for(i = 0; i < 8; i++)
scanf("%lf", &arr[i]);
for(i = 0; i < 8; i++)
printf("%.2f\t", arr[i]);
printf("\n");
sum[0] = arr[0];
for(i = 0; i < 7; i++) {
sum[i+1] = arr[i+1] + sum[i];
printf("%.2f\t", sum[i]);
}
printf("%.2f\n", sum[i]);
return 0;
}
#include
int main() {
int i = 0;
char str[256];
while(scanf("%c", &str[i]) && str[i] != '\n')
i++;
for(i--; i >= 0; i--)
printf("%c", str[i]);
printf("\n");
return 0;
}
#include
int main() {
int i = 0;
double Dalphne = 100.0, Deirdre = 100.0;
while(Dalphne >= Deirdre) {
Dalphne += 100 * 0.1;
Deirdre *= 1.05;
i++;
}
printf("%d years later, Deirdre is more investment than Dalphne.\n", i);
return 0;
}
#include
int main() {
int i = 0;
double Chuckie = 1e6;
while(Chuckie >= 0) {
Chuckie *= 1.08;
Chuckie -= 1e5;
i++;
}
printf("%d years later, Chuckie will have no deposit.\n", i);
return 0;
}
#include
int main() {
int friends = 5, i = 1;
while(friends < 150) {
friends -= i;
friends *= 2;
printf("In week %d, Rabnud has %d friends.\n", i, friends);
i++;
}
return 0;
}
C Primer Plus(第六版)