输入正方形边长编程计算正方形的周长(用编程计算正方形的面积)

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

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语言程序。

#includestdio.h

main(){

float

i;

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

scanf("%f",i);

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

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

}

输入正方形边长求面积周长c语言编程

#include?stdio.h

int?main(){

????double?d,?c,?s;

????printf("输入边长:");

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

????c?=?4?*?d;

????s?=?d?*?d;

????printf("周长:%.2lf,面积:%.2lf\n",?c,?s);

????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#输入正方形的边长求正方形的面积和周长

正方形的面积=正方形的边长×边长。 正方形的周长=正方形的边长×4.

编程求正方形的面积和周长,从键盘上输入正方形的边长d,然后计算正方形面积和周长?

正方形的面积和周长可以通过如下程序来求解:

#include iostream

using namespace std;

int main() {

double sideLength;

cout "请输入正方形的边长:" endl;

cin sideLength;

double area = sideLength * sideLength;

double perimeter = sideLength * 4;

cout "正方形的面积是:" area endl;

cout "正方形的周长是:" perimeter endl;

return 0;

}

在这段代码中,我们首先从键盘输入正方形的边长,然后计算出正方形的面积和周长,最后输出结果。

请注意,在 C++ 中,需要使用 #include iostream 来包含标准输入输出库,并使用 using namespace std; 来使用标准命名空间。

(责任编辑:IT教学网)

更多

推荐编程综合文章