C Language Sixth time assignment

Source: Internet
Author: User
Tags greatest common divisor pow

Job A:

1. Write the function int oddsum (int n) to calculate all the odd numbers in n integers and. The value of the n number is entered by the user from the keyboard.

#include <stdio.h>intMain () {intn,i,a,sum=0; printf ("you need to enter several numbers:"); scanf ("%d",&N);  for(i=1; i<=n;i++) {printf ("Please enter the number you entered:"); scanf ("%d",&a); if(a%2!=0) {sum=sum+A; }} printf ("n an odd number and is:%d", sum); return 0;} 

2. Write the function double Mypow (double x,int n) to calculate the n-th square of X (Note: the POW () function cannot be borrowed).

#include <stdio.h>DoubleMypow () {Doublex,y=1; intN,i; printf ("Please enter the base and index:"); scanf ("%lf%d",&x,&N);  for(i=1; i<=n;i++) y=y*x; printf ("%f", y);}intMain () {Mypow (); return 0;}

3. Write a function double cylinder (double r,double height) to calculate the volume of a cylinder with a radius of R and height.

#include <stdio.h>#include<math.h>#definePi 3.14Doublecylinder () {Doubler,h,v; printf ("Please enter radius and height:"); scanf ("%LF%LF",&r,&h); V=pi*pow (R,2)*h; printf ("the volume of the cylinder is:%f\n", v);}intMain () {cylinder (); return 0;}

Job B: Job Management system

#include <stdio.h>voidQues_1 () {printf ("1, max \ n"); printf ("2, ask m to n sum \ n"); printf ("3, averaging \ n");}voidques_2 () {printf ("C language theory homework \ n");}voidQues_3 () {printf ("1, 10 row triangle \ n"); printf ("2, 10 rows, 10 column rectangle \ n"); printf ("3, 10 rows inverted triangular shape \ n"); printf ("4, five grade results (a~e), output corresponding percentile score (0~100) zone \ n"); printf ("5, Fahrenheit temperature conversion Celsius temperature \ n"); printf ("6,100 m free fall \ n"); printf ("7, the value of the single-digit , 10-digit, and hundred digits of the output integer \ n"); printf ("8, segmented function \ n"); printf ("9, calculate deposit interest \ n"); printf ("10, step electricity price \ n"); }voidQues_4 () {printf ("1, guessing games/n"); printf ("2, greatest common divisor, least common multiple/n");}voidQues_5 () {printf ("1, after-school question 1/n"); printf ("2, after-school question 2/n"); printf ("3, after-school question 3/n"); printf ("4, after-school question 4/n"); printf ("5, after-school question 5/n"); printf ("6, use the double loop to print the triangle \ n"); }voidA () {intchoice; printf ("Please select a few jobs: \ n"); printf ("1, first assignment. \ n"); printf ("2, second assignment. \ n"); printf ("3, third job. \ n"); printf ("4, Fourth assignment. \ n"); printf ("5, Fifth assignment. \ n"); scanf ("%d",&choice); Switch(choice) { Case 1: Ques_1 ();  Break;  Case 2: Ques_2 ();  Break;  Case 3: Ques_3 ();  Break;  Case 4: Ques_4 ();  Break;  Case 5: Ques_5 ();  Break; default: printf ("The job does not exist.");  Break; } }intMain () {a (); return 0;}

This homework to do more laborious, in the editing process found a lot of problems, through the exchange with classmates to solve, there are some doubts, in the assignment B, do not know how to write the code written in printf, can not print the previous job, the remaining problems in the exchange with the students to be resolved.

C Language Sixth time assignment

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.