for形式
#include<stdio.h>
int main()
{
int sum = 0;
int i = 1;
int flag = 1;
for(i=1;i<=100;sum=sum+i*flag,i++,flag=-flag)
{
}
printf(" %d\n",sum);
return 0;
}
#include<stdio.h>
int main()
{
int sum = 0;
int i = 1;
int flag = 1;
for(i=1;i<=100;sum=sum+i*flag,i++,flag=-flag)
{
}
printf(" %d\n",sum);
return 0;
}
2021-11-09
#include <stdio.h>
int main()
{
int arr[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
int i,j;
int sum=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++){
if(i==j||i+j==2)
sum+=arr[i][j];
}
}
printf("对角线元素之和是:%d\n",sum);
return 0;
}
int main()
{
int arr[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
int i,j;
int sum=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++){
if(i==j||i+j==2)
sum+=arr[i][j];
}
}
printf("对角线元素之和是:%d\n",sum);
return 0;
}
2021-11-08
#include <stdio.h>
int main ()
{
double NUM= 2.5;
int num= (int)NUM;
printf("num的整数部分是%d\n ",num);
return 0 ;
}
int main ()
{
double NUM= 2.5;
int num= (int)NUM;
printf("num的整数部分是%d\n ",num);
return 0 ;
}
2021-11-06
顶级无语,根本不行好吗,我弄一个在别的地方可以运行成功的程序放到这里来都运行失败,兄弟姐妹们,别浪费时间了,这一课的练习就是有问题,无论怎么运行都是失败的
2021-11-05
#include<stdio.h>
int main()
{
double num=2.5;
int b=(int)num;
printf("%d\n,"b)
return 0;
}
int main()
{
double num=2.5;
int b=(int)num;
printf("%d\n,"b)
return 0;
}
2021-11-05
#include <stdio.h>
int main()
{
double num = 2.5; //定义浮点型变量num并赋值为2.5
int numTwo = (int)num;//强制转换为int类型
printf("num的整数部分是%f\n", num);
printf("numTwo的整数部分是%d\n",numTwo);
return 0;
}
int main()
{
double num = 2.5; //定义浮点型变量num并赋值为2.5
int numTwo = (int)num;//强制转换为int类型
printf("num的整数部分是%f\n", num);
printf("numTwo的整数部分是%d\n",numTwo);
return 0;
}
2021-11-04
#include <stdio.h>
int main()
{
char c = 'a';
int n = c; //将c赋值给n
float f = n; //将c赋值给f
double d = f; //将c赋值给d
printf("%d\n",n);
printf("%f\n",f);
printf("%lf\n",d);
return 0;
}
int main()
{
char c = 'a';
int n = c; //将c赋值给n
float f = n; //将c赋值给f
double d = f; //将c赋值给d
printf("%d\n",n);
printf("%f\n",f);
printf("%lf\n",d);
return 0;
}
2021-11-04
#include <stdio.h>
#define POCKETMONEY 10 //定义常量及常量值
int main()
{
printf("小明今天又得到%d元零花钱\n", POCKETMONEY);
return 0;
}
#define POCKETMONEY 10 //定义常量及常量值
int main()
{
printf("小明今天又得到%d元零花钱\n", POCKETMONEY);
return 0;
}
2021-11-04
评论有一个通病,就是当m=n的时候,m%n也=0,这样就执行break了,不会输出想要的素数。应该是m%n=0并且m≠n break。
2021-10-31
#include <stdio.h>
void printLine();
extern void say(){
printLine();
printf("I love imooc\n");
printf("good good study!\n");
printf("day day up!\n");
printLine();
}
void printLine();
extern void say(){
printLine();
printf("I love imooc\n");
printf("good good study!\n");
printf("day day up!\n");
printLine();
}
2021-10-30
#include <stdio.h>
void say();
extern void printLine() //这里定义的方法对吗?
{
printf("**************\n");
}
int main()
{
say();
return 0;
}
void say();
extern void printLine() //这里定义的方法对吗?
{
printf("**************\n");
}
int main()
{
say();
return 0;
}
2021-10-30