这样不更加简单?????
#include <stdio.h>
int main()
{
printf(" * \n");
printf(" *** \n");
printf(" ***** \n");
printf("*******\n");
return 0;
}
#include <stdio.h>
int main()
{
printf(" * \n");
printf(" *** \n");
printf(" ***** \n");
printf("*******\n");
return 0;
}
2021-11-16
#include <stdio.h>
float DayMoney(int x)
{
float Price=2.3*x+14;
return Price;
}
float NightMoney(int x)
{
float Price=2.3*1.2*x+14;
return Price;
}
float DayMoney(int x)
{
float Price=2.3*x+14;
return Price;
}
float NightMoney(int x)
{
float Price=2.3*1.2*x+14;
return Price;
}
int main()
{
float x=(12)-3;//括号内输入公里数;
float a=DayMoney(x);
float b=NightMoney(x);
printf("白天的车费是%f元\n",a);
printf("夜间的车费是%f元\n",b);
printf("全天的车费是%f元\n",a+b);
return 0;
}
{
float x=(12)-3;//括号内输入公里数;
float a=DayMoney(x);
float b=NightMoney(x);
printf("白天的车费是%f元\n",a);
printf("夜间的车费是%f元\n",b);
printf("全天的车费是%f元\n",a+b);
return 0;
}
#include <stdio.h>
int x=77;
void fn1()
{
printf("fn1():x=%d\n",x);
}
int main ()
{
int x=10;
if(x>0)
{
int x=100;
x/=2;
printf("if语句内,x=%d\n",x);
}
printf("main语句内,x=%d\n",x);
fn1();
return 0;
}
int x=77;
void fn1()
{
printf("fn1():x=%d\n",x);
}
int main ()
{
int x=10;
if(x>0)
{
int x=100;
x/=2;
printf("if语句内,x=%d\n",x);
}
printf("main语句内,x=%d\n",x);
fn1();
return 0;
}
2021-11-15
#include <stdio.h>
int getAgoNumber(int n)
{
int num;
if (n==1)
{
int num=10;
return num;
}
else
{
num=getAgoNumber(n-1)+2;
printf("第%d个人是%d岁\n",n,num);
}
return num ;
}
int main()
{
int num = getAgoNumber(5);
printf("第五个人是%d岁\n",num);
return 0 ;
}
int getAgoNumber(int n)
{
int num;
if (n==1)
{
int num=10;
return num;
}
else
{
num=getAgoNumber(n-1)+2;
printf("第%d个人是%d岁\n",n,num);
}
return num ;
}
int main()
{
int num = getAgoNumber(5);
printf("第五个人是%d岁\n",num);
return 0 ;
}
2021-11-14
#include <stdio.h>
int getGirth(int a,int b,int c)
{
if((a+b)<=c||(a+c)<=b||(b+c)<=a)
{
printf ("不构成三角形\n");
return 0 ;
}
else
{
int cirf =a+b+c;
return cirf;
}
}
int main ()
{
int a, b, c;
a= 3;
b= 4;
c= 5;
printf("三角形的周长是:%d\n",getGirth(a,b,c));
return 0 ;
}
int getGirth(int a,int b,int c)
{
if((a+b)<=c||(a+c)<=b||(b+c)<=a)
{
printf ("不构成三角形\n");
return 0 ;
}
else
{
int cirf =a+b+c;
return cirf;
}
}
int main ()
{
int a, b, c;
a= 3;
b= 4;
c= 5;
printf("三角形的周长是:%d\n",getGirth(a,b,c));
return 0 ;
}
#include <stdio.h>
int Study()
{
printf ("小明在慕课网上学习\n");
return 0 ;
}
int Ce(int n)
{
printf ("小明在慕课网上学习了%d门课程\n",n);
return 0 ;
}
int main ()
{
Study();
Ce(16); //你想要小明学习几门课程?
return 0 ;
}
int Study()
{
printf ("小明在慕课网上学习\n");
return 0 ;
}
int Ce(int n)
{
printf ("小明在慕课网上学习了%d门课程\n",n);
return 0 ;
}
int main ()
{
Study();
Ce(16); //你想要小明学习几门课程?
return 0 ;
}
#include <stdio.h>
int sayLove()
{
printf ( "%s\n","I Love imooc");
return 0;
}
int dividLine()
{
printf("%s\n","***********");
return 0 ;
}
int main ()
{
dividLine();
sayLove();
dividLine();
return 0 ;
}
int sayLove()
{
printf ( "%s\n","I Love imooc");
return 0;
}
int dividLine()
{
printf("%s\n","***********");
return 0 ;
}
int main ()
{
dividLine();
sayLove();
dividLine();
return 0 ;
}
#include <stdio.h>void say();extern void printLine(){printf("**************\n"); }int main(){say();return 0;}
#include <stdio.h>extern void printLine();void say(){printLine();printf("I love imooc\n");printf("good good study!\n");printf("day day up!\n");printLine();}在两个源文件里面声明所引用的外部函数第二个预编译命令删掉就行了。
#include <stdio.h>extern void printLine();void say(){printLine();printf("I love imooc\n");printf("good good study!\n");printf("day day up!\n");printLine();}在两个源文件里面声明所引用的外部函数第二个预编译命令删掉就行了。
2021-11-13
一个高级点的:
int fen;
printf("请输入玩家的分数:");
scanf("%d",&fen);
if (fen>=10000)
{
printf("%s\n","砖石玩家");
}
else if(fen>=5000&&fen<10000)
{
printf("%s\n","白金玩家");
}
else if(fen>=1000&&fen<5000)
{
printf("%s\n","青铜玩家");
}
else
{
printf("%s\n","普通玩家");
}
return 0;
}
int fen;
printf("请输入玩家的分数:");
scanf("%d",&fen);
if (fen>=10000)
{
printf("%s\n","砖石玩家");
}
else if(fen>=5000&&fen<10000)
{
printf("%s\n","白金玩家");
}
else if(fen>=1000&&fen<5000)
{
printf("%s\n","青铜玩家");
}
else
{
printf("%s\n","普通玩家");
}
return 0;
}
2021-11-12
#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&&i+j==2)
sum=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&&i+j==2)
sum=sum+arr[i][j];
}
}
printf("对角线元素之和是:%d\n",sum);
return 0;
}
2021-11-11
答案和过程对就完事
//使用while循环
while(i<=100)
{
i++;
if(i%2 == 1)
{
sum -= i;
}
else
{
sum += i;
}
}
//使用while循环
while(i<=100)
{
i++;
if(i%2 == 1)
{
sum -= i;
}
else
{
sum += i;
}
}
2021-11-11
#include<stdio.h>
int main()
{
int i = 0;
int k = 0;
for (i = 1; i <= 9; i++)
{
for (k = 1; k <= i; k++)
{
printf("%d*%d=%d\t", i, k, i * k);
}
printf("\n");
}
return 0;
}
int main()
{
int i = 0;
int k = 0;
for (i = 1; i <= 9; i++)
{
for (k = 1; k <= i; k++)
{
printf("%d*%d=%d\t", i, k, i * k);
}
printf("\n");
}
return 0;
}
2021-11-09