zoukankan      html  css  js  c++  java
  • 例2-9 累乘

    累乘

    程序核心——循环语句

    程序

    #include<stdio.h>
    int main()
    {
    	int i,n;
    	double product;
    	
    	printf("Enter n:");
    	scanf("%d",&n); 
    	product=1;
    	for(i=1;i<=n;i++)
    	{
    		product=product*i;
    	}
    	
    	printf("product=%.0f
    ",product);//指定输出不用小数 
    	return 0;
     } 
    

    结果

    Enter n:4
    product=24
    
    --------------------------------
    Process exited after 2.507 seconds with return value 0
    请按任意键继续. . 
    

    分析

    重点:printf("product=%.0f ",product)中%.0f指定输出不用小数,%.nf(n为常数)为指定保 留多少位小数,而若为%nf时固定至少有n位整数如不足n位用空格补齐

  • 相关阅读:
    货币系统
    纸牌
    活动
    KKT-黑白球
    POJ2676-Sudoku
    POJ1717-Dominoes
    POJ1088-滑雪
    POJ1862-Stripies
    POJ2531-Network Saboteur
    2019.12.13 数的划分
  • 原文地址:https://www.cnblogs.com/5236288kai/p/10531575.html
Copyright © 2011-2022 走看看