其他分享
首页 > 其他分享> > C语言电话线个数

C语言电话线个数

作者:互联网

#include <stdio.h>

int main(int argc, char *argv[]) {

	int totalLines,additionalLines,n1,n;
	//总共的电话线 
	printf("please input the number of telephones: ");
	scanf("%d",&n1);
	totalLines=n1*(n1-1)/2;
	//结果 
	printf("The number of direct lines required for %d telephones is %d\n",n1,totalLines);
    // 额外的电话线 
	printf("please input the number of new telephones: ");
	scanf("%d",&n); 
	additionalLines=(n1+n)*(n1+n-1)/2-n1*(n1-1)/2;
	//结果 
	printf("The number of additional lines required for %d new telephones is %d\n",n,additionalLines);
	
	return 0;
}
	

标签:totalLines,int,个数,number,C语言,telephones,printf,n1,电话线
来源: https://blog.csdn.net/m0_62796003/article/details/122520402