A very simple question of C language

Source: Internet
Author: User

C language is very simple several questions (or write), relatively simple, mainly have several questions of the data type (for example, the third problem) and the order of the sentence (for example, the second problem) need to pay attention to a small down.

  • 1. When the value of the expression S=1*2*3......*n is greater than 150, the value of the smallest n
    1 /*2 1. When the value of the expression S=1*2*3......*n is greater than 150, the value of the smallest n3 */4#include <stdio.h>5 voidMain () {6     intn=1, s=1;7      while(s<= Max){8s*=N;9n++;Ten     } Oneprintf"%d", N-1); A getch (); -}

  • 2. The value of the expression 1/1+1/2+1/3......+1/n is greater than 3 o'clock, and the minimum number of items required
    1 /*2 2. The value of the expression 1/1+1/2+1/3......+1/n is greater than 3 o'clock, and the minimum number of items required3 */4#include <stdio.h>5 voidMain () {6     floatn=0, s=0;7      while(s<=3){8n++;9s=s+1/N;Ten         //Note the order of accumulation and self-increment, which need to be changed according to the initial value of n One     } Aprintf"%d",(int) n); - getch (); -}

  • 3. According to media releases, China's GDP totaled $5.845 trillion in 2010, an increase of 10.1%,
    US GDP totaled $14.536 trillion, a growth rate of 3.3%. At a time when the GDP of both countries remained unchanged for 2010 years,
    What is the earliest year that China's GDP is expected to exceed US GDP?

    1 /*2 3. According to media releases, China's GDP totaled $5.845 trillion in 2010, 10.1% growth rate,3 US GDP totaled $14.536 trillion, a growth rate of 3.3%. At a time when the GDP of both countries remained unchanged for 2010 years,4 What is the earliest year that China's GDP is expected to exceed US GDP? 5 */ 6 //7#include <stdio.h>8 voidMain () {9     floatC=5.845, a=14.536, cg=0.101, ag=0.033;Ten     inty= .; One      while(c<=a) { Ac+=c*CG; -a+=a*AG; -y++; the     } -printf"%d", y); - getch (); -}

  • 4. Evaluates the value of the expression S=1+2+3+4......+n, and the value of n is entered by the keyboard
    1 /*2 4. Evaluates the value of the expression S=1+2+3+4......+n, and the value of n is entered by the keyboard3 */4#include <stdio.h>5 voidMain () {6     inti,n,s=0;7scanf"%d",&n);8      for(i=1; i<=n;i++){9s+=i;Ten     } Oneprintf"%d", s); A getch (); -}

  • 5. Find the expression s=1!+2!+3!...... +n!,n typed by the keyboard
    1 /*2 5. Find the expression s=1!+2!+3!...... +n!,n typed by the keyboard3 */4#include <stdio.h>5 voidMain () {6     inti,j=1, s=0, N;7scanf"%d",&n);8      for(i=1; i<=n;i++){9j*=i;Tens+=J; One     } Aprintf"%d", s); - getch (); -}

A very simple question of C language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.