2504C语言任务(0417)

Viewed 179

任务一(程序改错)

下面程序为变量x,y,z赋初值2.5,然后在屏幕上打印这些变量的值。程序中存在错误,请改正错误并在代码中以注释进行说明,写出程序的正确运行结果

#include<stdio.h>
int main(){
	printf("THese values are: \n");
	int x = y = z = 2.5;
	printf("x = %d \n",x);
	printf("y = %d \n",y);
	printf("z = %d \n",z);
	return 0; 
}

任务二(第三章:课后习题第六题)

请编程序将“China”译成密码,密码规律是:用原来的字母后面第4个字母代替原来的字母。例如,字母“A”后面第4个字母是“E”,用“E”代替“A”。因此,“China”应译为“Glmre”。请编一程序,用赋初值的方法使c1,c2,c3,c4,c5这5个变量的值分别为'C','h','i','n','a',经过运算,使c1,c2,c3,c4,c5分别变为'G','1','m','r','e'。分别用putchar函数和printf 函数输出这5个字符。

24 Answers
#include<stdio.h> //编译预处理指令 
int main(){ //定义主函数并开始 
	printf("THese values are: \n");  //输出THese values are: 
	int x,y,z; //定义xyz三个变量 
	x = y = z = 2.5; //定义变量的值为2.5 
	printf("x = %d \n",x); //输出x的整数值 
	printf("y = %d \n",y); //输出y的整数值 
	printf("z = %d \n",z); //输出z的整数值 
	return 0; //返回函数值为0 
} //函数结束 

输出的内容为:
THese values are:
x = 2
y = 2
z = 2
请按任意键继续. . .

#include<stdio.h> //编译预处理指令 
int main(){ //定义主函数并开始 
	printf("THese values are: \n");  //输出THese values are: 
	double x,y,z; //定义xyz三个变量 
	x = y = z = 2.5; //定义变量的值为2.5 
	printf("x = %.1f \n",x); //输出x2.5 
	printf("y = %.1f \n",y); //输出y2.5
	printf("z = %.1f \n",z); //输出z2.5 
	return 0; //返回函数值为0 
} //函数结束 

输出的内容为:
THese values are:
x = 2.5
y = 2.5
z = 2.5
请按任意键继续. . .

#include<stdio.h> //编译预处理指令 
int main(){ //定义主函数并开始 
	printf("THese values are: \n");  //输出THese values are: 
	int x,y,z; //定义xyz三个变量 
	x = y = z = 2.5; //定义变量的值为2.5 
	printf("x = %d \n",x); //输出x的整数值 
	printf("y = %d \n",y); //输出y的整数值 
	printf("z = %d \n",z); //输出z的整数值 
	return 0; //返回函数值为0 
} //函数结束 

输出的内容为:
THese values are:
x = 2
y = 2
z = 2
请按任意键继续. . .

#include<stdio.h> //编译预处理指令 
int main(){ //定义主函数并开始 
	printf("THese values are: \n");  //输出THese values are: 
	double x,y,z; //定义xyz三个变量 
	x = y = z = 2.5; //定义变量的值为2.5 
	printf("x = %.1f \n",x); //输出x2.5 
	printf("y = %.1f \n",y); //输出y2.5
	printf("z = %.1f \n",z); //输出z2.5 
	return 0; //返回函数值为0 
} //函数结束 

输出的内容为:
THese values are:
x = 2.5
y = 2.5
z = 2.5
请按任意键继续. . .

#include <stdio.h>

int main() {
// 赋初值:c1~c5 分别为 'C', 'h', 'i', 'n', 'a'
char c1 = 'C';
char c2 = 'h';
char c3 = 'i';
char c4 = 'n';
char c5 = 'a';

// 按规则:每个字母替换为后面第4个字母
c1 = c1 + 4;
c2 = c2 + 4;
c3 = c3 + 4;
c4 = c4 + 4;
c5 = c5 + 4;

// 用 putchar 函数输出
printf("用 putchar 输出:");
putchar(c1);
putchar(c2);
putchar(c3);
putchar(c4);
putchar(c5);
putchar('\n'); // 换行

// 用 printf 函数输出
printf("用 printf 输出:%c%c%c%c%c\n", c1, c2, c3, c4, c5);

return 0;

}
输出结果为:
用 putchar 输出:Glmre
用 printf 输出:Glmre
请按任意键继续. . .

#include<stdio.h>
int main(){
printf("THese values are: \n");
int x, y, z;
x = y = z = 2.5;
printf("x = %d \n",x);
printf("y = %d \n",y);
printf("z = %d \n",z);
return 0;
}

生气的符号

#include <stdio.h>
int main(){
char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';
  c1 +=4;
  c2 +=4;
  c3 +=4;
  c4 +=4;
  c5 +=4;
  printf("putchar 输出: ");
  putchar(c1);
  putchar(c2);
  putchar(c3);
  putchar(c4);
  putchar(c5);
  printf("printf 输出: %c%c%c%c%c\n,c1, c2, c3, c4, c5,");
   return 0;
}
`
# 任务一改错

#include<stdio.h>
int main(){
printf("THese values are: \n");
//应该分开定义这些值。
double x = 2.5,y =2.5, z = 2.5;
// 格式字符应该用%f
printf("x = %f \n",x);
printf("y = %f \n",y);
printf("z = %f \n",z);
return 0;
}

#include<stdio.h>//编译预处理指令
int main(){//定义主函数,开始主函数 
	printf("THese values are: \n");//输出THese values are: 
	double x,y,z;//定义x,y,z
	x = y = z = 2.5;//定义x,y,z,的值为2.5 
	printf("x = %d \n",x);//输出x的值 
	printf("y = %d \n",y);//输出y的值
	printf("z = %d \n",z);//输出z的值
	return 0;//返回函数值为0 
}//结束主函数
输出的结果:
THese values are:
x=2.5
y=2.5
z=2.5

good boy

#include<stdio.h>//编译预处理指令 
int main(){	//定义主函数,开始主函数 
	printf("THese values are: \n");//输出THese values are: 
	double x,y,z;//定义x,y,z 
	x = y = z = 2.5;//定义x,y,z的值为2.5 
	printf("x = %.1f \n",x);//输出x的值 
	printf("y = %.1f \n",y);//输出y的值
	printf("z = %.1f \n",z);//输出z的值
	return 0;//返回函数值为0 
}//结束主函数

输出的结果:
THese values are:
x = 2.5
y = 2.5
z = 2.5
请按任意键继续. . .

good girl

标题 1

#include<stdio.h>
int main(){
	printf("THese values are: \n");
	int x =2.5, y =2.5, z = 2.5;
	printf("x = %d \n",x);
	printf("y = %d \n",y);
	printf("z = %d \n",z);
	return 0; 
}
## 标题 2
#include <stdio.h>

int main() {
    // 赋初值
    char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';

    // 密码规律:每个字母后面第4个字母代替原来的字母
    c1 += 4;
    c2 += 4;
    c3 += 4;
    c4 += 4;
    c5 += 4;

    // 使用putchar输出
    printf("使用putchar输出:\n");
    putchar(c1);
    putchar(c2);
    putchar(c3);
    putchar(c4);
    putchar(c5);
    printf("\n");

    // 使用printf输出
    printf("使用printf输出:\n");
    printf("%c%c%c%c%c\n", c1, c2, c3, c4, c5);

    return 0;
}

## 标题 2

答案很正确,能够注意格式就更完美了

标题1
#include<stdio.h>
int main(){
printf("THese values are: \n");
int x =2.5, y =2.5, z = 2.5;
printf("x = %d \n",x);
printf("y = %d \n",y);
printf("z = %d \n",z);
return 0;
}
标题2
#include <stdio.h>

int main() {
// 1. 赋初值:c1~c5 分别为 C, h, i, n, a
char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';

// 2. 翻译密码:每个字符 +4(ASCII码自动运算)
c1 = c1 + 4;
c2 = c2 + 4;
c3 = c3 + 4;
c4 = c4 + 4;
c5 = c5 + 4;

// 3. 使用 putchar 函数输出
printf("putchar 输出结果:");
putchar(c1);
putchar(c2);
putchar(c3);
putchar(c4);
putchar(c5);
putchar('\n');  // 换行

// 4. 使用 printf 函数输出
printf("printf 输出结果:%c%c%c%c%c\n", c1, c2, c3, c4, c5);

return 0;

}

第二个任务的代码要注意放一块

#include<stdio.h>
int main(){
printf("THese values are: \n");
int x, y, z;
x = y = z = 2;
printf("x = %d \n",x);
printf("y = %d \n",y);
printf("z = %d \n",z);
return 0;
}

第一个任务没问题,但是要注意标明任务

printf("THese values are: \n")
//printf应该放到return 0上方

结果:x=2 y=2 z=2

注意答题格式哦

printf("There values are: \n")
printf放在return 0的上方
结果:x=2 y=2 z=2

标题一
#include<stdio.h>
int main(){
printf("These values are: \n"); // 补充分号,修正拼写错误
double x, y, z; // 定义双精度(double)变量
x = y = z = 2.5; // 给三个变量赋值2.5
printf("x = %lf\n", x); // 双精度用%f输出
printf("y = %lf\n", y); // 双精度用%f输出
printf("z = %lf\n", z); // 双精度用%f输出
return 0;
}

标题二
#include <stdio.h>
int main() {
// 赋初值:c1~c5 分别为 'C','h','i','n','a'
char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';

 // 加密:每个字符向后移动4位
 c1 += 4;
 c2 += 4;
 c3 += 4;
 c4 += 4;
 c5 += 4;
 
 // 用putchar函数输出
 printf("使用putchar输出:");
 putchar(c1);
 putchar(c2);
 putchar(c3);
 putchar(c4);
 putchar(c5);
 printf("\n");
 
 // 用printf函数输出
 printf("使用printf输出:%c%c%c%c%c\n", c1, c2, c3, c4, c5);
 
 return 0;

}

任务一的回答

#include<stdio.h>
int main(){
	printf("THese values are: \n");
        // 定义变量这里,要分开定义
	float x =2.5, y =2.5, z = 2.5;
        // 输出函数这里,要使用对应的格式字符
	printf("x = %f \n",x);
	printf("y = %f \n",y);
	printf("z = %f \n",z);
	return 0; 
}

任务二的回答

#include <stdio.h>
int main() {
    // 赋初值
    char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';
    // 密码规律:每个字母后面第4个字母代替原来的字母
    c1 += 4;
    c2 += 4;
    c3 += 4;
    c4 += 4;
    c5 += 4;
    // 使用putchar输出
    printf("使用putchar输出:\n");
    putchar(c1);
    putchar(c2);
    putchar(c3);
    putchar(c4);
    putchar(c5);
    printf("\n");
    // 使用printf输出
    printf("使用printf输出:\n");
    printf("%c%c%c%c%c\n", c1, c2, c3, c4, c5);
    return 0;
}

good girl

标题 1#include<stdio.h> //编译预处理指令

int main(){ //定义主函数并开始
printf("THese values are: \n"); //输出THese values are:
double x,y,z; //定义xyz三个变量
x = y = z = 2.5; //定义变量的值为2.5
printf("x = %.1f \n",x); //输出x2.5
printf("y = %.1f \n",y); //输出y2.5
printf("z = %.1f \n",z); //输出z2.5
return 0; //返回函数值为0
}

标题 2#include <stdio.h>
int main(){
char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';
c1 +=4;
c2 +=4;
c3 +=4;
c4 +=4;
c5 +=4;
printf("putchar 输出: ");
putchar(c1);
putchar(c2);
putchar(c3);
putchar(c4);
putchar(c5);
printf("printf 输出: %c%c%c%c%c\n,c1, c2, c3, c4, c5,");
return 0;
}

#include<stdio.h>

int main(){
printf("THese values are: \n");
// 定义变量这里,要分开定义
float x =2.5, y =2.5, z = 2.5;
// 输出函数这里,要使用对应的格式字符
printf("x = %f \n",x);
printf("y = %f \n",y);
printf("z = %f \n",z);
return 0;
}
任务2
#include <stdio.h>
int main() {
// 赋初值
char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';
// 密码规律:每个字母后面第4个字母代替原来的字母
c1 += 4;
c2 += 4;
c3 += 4;
c4 += 4;
c5 += 4;
// 使用putchar输出
printf("使用putchar输出:\n");
putchar(c1);
putchar(c2);
putchar(c3);
putchar(c4);
putchar(c5);
printf("\n");
// 使用printf输出
printf("使用printf输出:\n");
printf("%c%c%c%c%c\n", c1, c2, c3, c4, c5);
return 0;
}

#include<stdio.h>
int main(){
printf("THese values are: \n");
// 定义变量这里,要分开定义
float x =2.5, y =2.5, z = 2.5;
// 输出函数这里,要使用对应的格式字符
printf("x = %f \n",x);
printf("y = %f \n",y);
printf("z = %f \n",z);
return 0;
}
任务2
#include <stdio.h>
int main() {
// 赋初值
char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';
// 密码规律:每个字母后面第4个字母代替原来的字母
c1 += 4;
c2 += 4;
c3 += 4;
c4 += 4;
c5 += 4;
// 使用putchar输出
printf("使用putchar输出:\n");
putchar(c1);
putchar(c2);
putchar(c3);
putchar(c4);
putchar(c5);
printf("\n");
// 使用printf输出
printf("使用printf输出:\n");
printf("%c%c%c%c%c\n", c1, c2, c3, c4, c5);
return 0;
}

标题 1#include<stdio.h>

int main(){
printf("THese values are: \n");
int x =2.5, y =2.5, z = 2.5;
printf("x = %d \n",x);
printf("y = %d \n",y);
printf("z = %d \n",z);
return 0;
}

标题 2

#include <stdio.h>

int main() {
// 赋初值
char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';

// 密码规律:每个字母后面第4个字母代替原来的字母
c1 += 4;
c2 += 4;
c3 += 4;
c4 += 4;
c5 += 4;

// 使用putchar输出
printf("使用putchar输出:\n");
putchar(c1);
putchar(c2);
putchar(c3);
putchar(c4);
putchar(c5);
printf("\n");

// 使用printf输出
printf("使用printf输出:\n");
printf("%c%c%c%c%c\n", c1, c2, c3, c4, c5);

return 0;

}

标题 2