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;
}
	

上一篇:C++实现5位整数分解


下一篇:博弈论