본문 바로가기
반응형

C basic10

5. Array and Functions[C Basic] 5.1. Write a program that produces 20 random numbers between 1 and 20. The program should store all non-duplicate values in an array (s.t., first value in Array[0], second value in Array[1], …) Use a single array to accomplish this task. #include #include #include int check_array(int array[],int i){ int j; for(j=0;j 2021. 11. 7.
4. Function[C Basic] 4.1. Define a function ‘hypotenuse’ that calculates the length of the hypotenuse of a right triangle when the other two sides are given The function should take two argument of type double and return the hypotenuse as a double #include #include double hypotenuse(double side1, double side2); int main() { int i; double n1, n2; for (i = 0;i < 3;i++) { printf("Enter the sides of the triangle : "); s.. 2021. 11. 7.
2. Loop[C Basic] 2.1. Write a program that (1) inputs two integers (integer1 and integer 2) (2) prints sum of all integers between integer1 and integer2 (3) Use while() statement #include int main() { int n1, n2, sum=0, temp; printf("Enter two integers : "); scanf("%d %d", &n1, &n2); temp = n1; if (n1 > n2) { temp = n2; n2 = n1; n1 = temp; } while (n1 0) { if (n % 10 == 7) cnt++; n /= 10; } printf("The number %d.. 2021. 11. 6.
1. Input and Output[C Basic] 1.1. Write a program that reads an integer and determines and prints whether it is odd or even. [Hint: Use the remainder operator. An even number is a multiple of two. Any multiple of two leaves a remainder of zero when divided by 2.] #include int main() { int a; printf("Input an integer : "); scanf("%d", &a); if (a % 2 == 0) printf("%d is an even integer", a); if(a % 2 == 1) printf("%d is an od.. 2021. 11. 6.
반응형