c语言正方形的周长和面积(c语言求正方形周长面积)

http://www.itjxue.com  2023-03-17 05:05  来源:未知  点击次数: 

求正方形边长,面积和周长的C语言程序。

#includestdio.h

main(){

float

i;

printf("请输入正方形一条边的长度");

scanf("%f",i);

printf("正方型的周长为:%4.2f\n",i*4);

printf("正方型的面积为:%4.2f\n",i*i);

}

如何用C语言求矩形的面积和周长

C语言计算矩形的面积和周长,是面试过程中常见的问题之一。其实矩形的面积和周长的计算公式,周长等于2x + 2y,矩形面积=长 x 宽。

周长是围绕二维图形的路径。周长可以用来计算包围一个院子或花园所需的栅栏的长度。对于只有两个边长的矩形,比如x和y,周长等于2x + 2y。矩形面积的公式使用乘法:长 x 宽 = 面积。有四条等边的长方形是正方形。矩形面积单位是平方米、平方厘米等等。

扩展资料:

C语言使用注意事项:

数组是有前后每个值的下标之间是有数学关联的。例如数组a第一个值的下标是i,数组长度为n,最末一个值的下标则是n-1-i。当i递增时,(n-1-i)也随着递减。

函数用数组作为参数,例如func(int a[]);本身就是把数组的地址传入函数中,所以如果修改,会修改原数组的内容。不会从新建立一个数组。

指针的地址必须由多级指针存放。例如int *p,**q,a=12;p=a;q=p。

参考资料来源:百度百科-c语言

参考资料来源:百度百科-矩形

参考资料来源:百度百科-矩形判定定理

用c语言求正方形的面积和周长

#include stidio.h

int fun(int a)

{

int s;

s=a*a;

return s;

}

void main()

{

int a;

printf("输入将要计算的正方形的边长:\n");

scanf("%d",s);

printf("正方形的面积为:%d",fun(a));

}

C语言编8个程序 比如输入正方形边长求其面积和周长 正方体求体积

//?第一个:求数字位数

#include?stdio.h????

#include?stdlib.h????

#include?stdbool.h????

#define?CRT_SECURE_NO_DEPERCATE????

int?main(void)????

{????

int?data;????

printf("Enter?a?number:");????

scanf("%d",data);????

if?(data=10000)????

{printf("Input?Error\n");system("pause");exit;}????

else?if?(data=1000)????

printf("The?number?%4d?has?4?numbers.\n");????

else?if?(data=100)????

printf("The?number?%4d?has?3?numbers.\n");????

else?if?(data=10)????

printf("The?number?%4d?has?2?numbers.\n");????

else?if?(data=1)????

printf("The?number?%4d?has?1?numbers.\n");????

else????{printf("Input?Error\n");system("pause");exit;}????

????

system("pause");????

return?0;????

}

//?第二个24小时制-AM/PM

#include?stdio.h????

#include?stdlib.h????

#include?stdbool.h????

#define?CRT_SECURE_NO_DEPERCATE????

int?main(void)????

{????

int?hour,minute;????

printf("Enter?a?24-hour?time:");????

scanf("%d:%d",hour,minute);????

switch?(hour)????

{????

case?0:case?1:case?2:case?3:case?4:case?5:case?6:case?7:case?8:case?9:case?10:case?11:case?12:????

printf("Equivalent?12-hour?time:?%-2.2d:%-2.2d?AM\n",hour,minute);break;????

case?13:case?14:case?15:case?16:case?17:case?18:case?19:case?20:case?21:case?22:case?23:????

printf("Equivalent?12-hour?time:?%-2.2d:%-2.2d?PM\n",hour-12,minute);break;????

case?24:????

printf("Equivalent?12-hour?time:?00:%-2.2d?AM\n",minute);break;????

default:????

printf("Input?Error\n");system("pause");exit;????

}????

system("pause");????

return?0;????

}

//?第三个比较日期前后

#define?CRT_SECURE_NO_DEPERCATE????

#include?stdio.h????

#include?stdlib.h????

#include?stdbool.h????

int?main(void)????

{????

int?year1,year2,month1,month2,day1,day2,p;????

printf("Enter??first?date?(mm/dd/yy):");????

scanf("%d/%d/%d",month1,day1,year1);????

printf("Enter?second?date?(mm/dd/yy):");????

scanf("%d/%d/%d",month2,day2,year2);????

if?(year1year2)???p=year1year2?1:2;????

else?if?(month1month2)?p=month1month2?1:2;????

else?if?(day1day2)?????p=day1day2?1:2;????

else?????????????????????p=0;????

switch?(p)????

{????

case?1:printf("%2d/%-2.2d/%4d?is?earlier?than?%2d/%-2.2d/%4d\n",month2,day2,year2,month1,day1,year1);break;????

case?2:printf("%2d/%-2.2d/%4d?is?earlier?than?%2d/%-2.2d/%4d\n",month1,day1,year1,month2,day2,year2);break;????

case?0:printf("They?are?definetely?equal.\n");break;????

}????

????

system("pause");????

return?0;????

}

//?第四个给分数评级

#define?_CRT_SECURE_NO_DEPERCATE?/*Before?all?the?includes*/????

#include?stdio.h????

#include?stdlib.h????

#include?stdbool.h????

int?main(void)????

{????

int?grade;????

_Bool?checkpoint;????

checkpoint=true;????

//Input????

while?(checkpoint)????

{????

printf("Enter?numerical?grade:");????

???? scanf("%d",grade);????

if?(grade0||grade100)?{printf("Input?Error,please?try?again\n");system("pause");}????

else?if?checkpoint=false;????

}????

//Output????

printf("Letter?grade:?");????

switch?(grade/10)????

{????

case?10:?case?9:printf("A");break;????

case??8:????????printf("B");break;????

case??7:????????printf("C");break;????

case??6:????????printf("D");break;????

default:????????printf("F");//Don't?wanna?a?break.....????

}????

printf("\n");????

//Pause????

system("pause");????

return?0;????

}

//?第五个用英文显示数字

#define?_CRT_SECURE_NO_DERECATE????

#include?stdio.h????

#include?stdlib.h????

#include?stdbool.h????

int?main(void)????

{????

int?input_number,first_digit,second_digit;????

bool?checkpoint;????

//input????

checkpoint=true;????

while?(checkpoint)????

{????

printf("Enter?a?two-digit?number:?");????

scanf("%d",input_number);????

if?(input_number0||input_number99)?{printf("Input?Error,please?try?again.\n");system("pause");}????

else?checkpoint=false;????

}????

//output????

printf("Your?entered?the?number?");????

if?(input_number=19)????

switch?(input_number)?//0-19????

{????

case??0:printf("zero");?????break;????

case??1:printf("one");??????break;????

case??2:printf("two");??????break;????

case??3:printf("three");????break;????

case??4:printf("four");?????break;????

case??5:printf("five");?????break;????

case??6:printf("six");??????break;????

case??7:printf("seven");????break;????

case??8:printf("eight");????break;????

case??9:printf("nine");?????break;????

case?10:printf("ten");??????break;????

case?11:printf("eleven");???break;????

case?12:printf("twelve");???break;????

case?13:printf("thirteen");?break;????

case?14:printf("forteen");??break;????

case?15:printf("fifteen");??break;????

case?16:printf("sixteen");??break;????

case?17:printf("seventeen");break;????

case?18:printf("eighteen");?break;????

case?19:printf("ninteen");??break;????

}????

else????

{????

first_digit=input_number/10;second_digit=input_number%10;????

switch?(first_digit)????

{????

case?2:printf("twenty");?break;????

case?3:printf("thirty");?break;????

case?4:printf("forty");??break;????

case?5:printf("fifty");??break;????

case?6:printf("sixty");??break;????

case?7:printf("seventy");break;????

case?8:printf("eighty");?break;????

case?9:printf("ninty");??break;????

}????

switch?(second_digit)????

{????

case?0:??????????????;??????break;????

case?1:printf("-one");??????break;????

case?2:printf("-two");??????break;????

case?3:printf("-three");????break;????

??? case?4:printf("-four");?????break;????

case?5:printf("-five");?????break;????

???? case?6:printf("-six");??????break;????

??? case?7:printf("-seven");????break;????

?? case?8:printf("-eight");????break;????

??? case?9:printf("-nine");?????break;????

}????

}????

printf("\n");????

????

//pause????

system("pause");????

return?0;????

}

//?第六个统计最大数字

#define?_CRT_SECURE_NO_DEPRECATE?/*Before?all?the?includes*/????

#include?stdio.h?/*scanf?printf*/????

#include?stdlib.h?/*system*/????

#include?stdbool.h?/*bool?true?false*/????

int?main(void)????

{????

float?input_data,?largest?=?0.0f;????

printf("This?program?is?used?to?caculate?the?largest?number?you?entered.\n");????

do????

{????

printf("Enter?a?number:");????

scanf("%f",?input_data);????

if?(input_datalargest)????

largest?=?input_data;????

}?while?(input_data0);????

if?(largest?==?0)?printf("Input?Error!");????

else?printf("The?largest?number?entered?was?%-5.2f\n",?largest);????

system("pause");????

return?0;????

}

//?第七个计算最大公约数

#define?_CRT_SECURE_NO_DEPRECATE?/*Before?all?the?includes*/????

#include?stdio.h?/*scanf?printf*/????

#include?stdlib.h?/*system*/????

#include?stdbool.h?/*bool?true?false*/???

int?main(void)????

{????

int?a=0,b=0,t;????

bool?checkpoint=false;????

do????

{????

printf("Enter?two?digits:");????

scanf("%d%d?",a,b);????

if?(a=1b=1)?checkpoint=true;?else?printf("Input?error,?please?try?again?with?mind.\n");????

}????

while?(!checkpoint);????

if?(ab)?{t=a;a=b;b=t;}????

while?(b!=0)????

{????

t=a%b;????

a=b;????

b=t;????

}????

printf("GCD(Greatest?common?divisor)?is?%d\n",a);????

????

system("pause");????

return?0;

}

//?第八最简化分数

#define?_CRT_SECURE_NO_DEPRECATE?/*Before?all?the?includes*/????

#include?stdio.h?/*scanf?printf*/????

#include?stdlib.h?/*system?abs*/????

#include?stdbool.h?/*bool?true?false*/

int?main(void)????

{????

int?a=0,b=0,t,point=0,former_a,former_b;????

bool?checkpoint=false;????

do????

{????

printf("Enter?a?fraction:");????

scanf("%d/%d",a,b);????

if?(b!=0)?checkpoint=true;?else?printf("Input?error,?please?try?again?with?mind.\n");????

}????

while?(!checkpoint);????

if?(a==0)?point=1;????

else?switch?((a0)+(b0))????

{????

case?1:point=2;?/*NO?break*/????

default:a=abs(a);b=abs(b);????

}????

printf("In?lowest?terms:?");????

switch?(point)????

{????

case?1:/*a==0*/????

printf("0\n");break;????

case?2:/*negative*/????

printf("-");????

case?0:????

former_a=a;????

former_b=b;????

if?(ab)?{t=a;a=b;b=t;}????

while?(b!=0)????

{????

t=a%b;????

??? a=b;????

b=t;????

??? }????

former_a=former_a/a;????

former_b=former_b/a;????

printf("%d",former_a);????

if?(former_b!=1)?printf("/%d",former_b);????

printf("\n");????

break;/*useless*/????

}????

system("pause");????

return?0;????

}

C语言编写程序,输入一个正方形的边长,输出其周长和面积

#include stdio.h

int main()

{

int l = 0;

print("请输入边长:\n");

scanf("%d", l);

int s = l * l;

int c = 4 *l;

printf("面积:%d 周长:%d\n", s, c);

return 0;

}

编写程序球正方形,长方形,梯形,圆形的周长和面积? 我是学习C语言的新手 麻烦高手给出源代码

不知道输入,输出格式是什么,就随便写了。

#includestdio.h

int main()

{

int choice=0;

float a,b,c;

while(true)

{

printf("1.正方形\n2.长方形\n3.梯形\n4.圆\n0.退出\n请选择:");

scanf("%d",choice);

switch(choice)

{

case 1:

printf("输入正方形的边长:");

scanf("%f",a);

while(a=0)

{

printf("错误!重新输入:");

scanf("%f",a);

}

printf("面积 = %.2f\n",a*a);

break;

case 2:

printf("输入长方形的长、宽:");

scanf("%f%f",a,b);

while(a=0||b=0)

{

printf("错误!重新输入:");

scanf("%f%f",a,b);

}

printf("面积 = %.2f\n",a*b);

break;

case 3:

printf("输入梯形的上底、下底、高:");

scanf("%f%f%f",a,b,c);

while(a=0||b=0||c=0)

{

printf("错误!重新输入:");

scanf("%f%f%f",a,b,c);

}

printf("面积 = %.2f",(a+b)*c/2);

break;

case 4:

printf("输入圆的半径:");

scanf("%f",a);

while(a=0)

{

printf("错误!重新输入:");

scanf("%f",a);

}

printf("面积",3.14*a*a);

break;

case 0:

return 0;

}

}

return 0;

}

(责任编辑:IT教学网)

更多

推荐Discuz!建站文章