Find two C programs, why can a C program have at least 2 functions?

Updated on technology 2024-05-09
8 answers
  1. Anonymous users2024-02-10

    *Find 2+4+6+8+....+100 and *

    #include ""

    void main()

    int n=100,i,s=0;Define integers n,i,s

    for(i=2;i<=100;i+=2) assigns an initial value = 2 to i, and when i<=100, whenever the following operations are completed, i=i+2 until i is greater than 100.

    s=s+i;Assign the value of s+i to s

    printf("2+4+6+8+…The sum of +100 is: %d",s);Outputs

    #include ""

    void main()

    int n,i,sum=0;

    printf("Please enter an integer:");

    scanf("%d",&n);

    for(i=0;i<=n;i++)

    sum+=1*i*(i+1)/2;Put 2 into the final guarantee calculation, always an integer, which probably means this, add up the sum corresponding to each n.

    printf("To 1+2+...d and the result is: %d",n,sum);

    Hope it works for you.

  2. Anonymous users2024-02-09

    The formula is there...

    The first. int a=0;int i;

    for(i=2;i<=100;i+=2)

    a=a+i;

    Second, isn't there a formula...

    int sum,n;

    scanf("%d",&n);

    sum=n*(n+1)/2;

    Write it down yourself, it takes practice.

  3. Anonymous users2024-02-08

    It's very simple, the first one is for(i=2; i<=100;i=i+2)sum+=i;

    The second one is incomprehensible with the formula sum=1 2*n*(n+1) to 1+2+.What does it mean to make a sum?

    If you want to know how to do it, just contact me!

  4. Anonymous users2024-02-07

    Use the C language to write a programming idea and method for finding the sum of two numbers

    1.First of all, you need to define three variables a, b, and c, two of which are the added numbers, and the third is the sum of the source checks obtained by the addition.

    2.The two numbers entered from the keyboard are then received using the scanf() statement, assigning values to the variables a,b.

    3.Next, the addition of a and b is performed to assign the result to the variable c.

    4.Finally, use the printf() statement to display the result on the screen.

    5.**After the writing is completed, click Run to see the running result of the program in the debugging window.

  5. Anonymous users2024-02-06

    To be precise: a C program must have at least one function, which is the main() function.

    C programs are made up of parallel functions.

    The execution of a C program starts with the population function, i.e. the main function main() and ends at the end of main().

    A C program is only allowed to have one function named main(). You can call other functions without being called by other functions. Therefore, the execution of a C program always starts with the main function, returns to the main function after completing the call to other functions, and finally ends the entire program with the main function.

    A C source program must have, and can only have, one main function, main.

    In C, because all function definitions, including the main function, are parallel. Therefore, within the body of a function, another function cannot be defined, i.e., it cannot be nested. However, functions are allowed to call each other, as well as nested calls.

    It is customary to refer to the caller as the main tone function and the callee as the tone function. Functions can also call themselves on their own, known as recursive calls.

  6. Anonymous users2024-02-05

    The main function is mandatory, and you can also customize the function.

  7. Anonymous users2024-02-04

    1. Enter a string of characters from the keyboard and count the number of words entered. Words are separated by spaces.

    Note: Only a simple space judgment is made, and no letter judgment is made, so non-letters will be considered as long as they are separated by spaces.

    #include

    int main()

    p++;cout<<"The entered string is:"<

    int main()

    elsereturn 0;}

  8. Anonymous users2024-02-03

    1, char str[100];

    int i,j=1;

    scanf("%c",str);

    for(i=0;i<100;i++)

    printf("Number of words = %d",j);

    2,int a,b;

    scanf("%d %d",&a,&b);

    if(a==b)

    printf("The two values are equal to %d",a);

Related questions
5 answers2024-05-09

Question 1: pt1=&a;pt2=&b;pt1 and pt2 are not defined, years are defined as. >>>More

7 answers2024-05-09

In the C language. An integer constant starting with 0 refers to octal. 027 is 2x8+7, so the answer is c.

3 answers2024-05-09

Your app is to deal cards to three people, one player, and two computers. 16 cards per person. >>>More

7 answers2024-05-09

char *p;

uchar log_type; >>>More

7 answers2024-05-09

In the whole main function, only this one variable, whether it is the first for or the second for, is the same i, the second for will have i=-1, in the case of i= -1, and printf("%d ",a[i]);Statement. So fear not! When there is no second for the case: >>>More