Question1:
#include <stdio.h> int main() { int num1, num2; scanf("%d", &num1); scanf("%d", &num2); while (num1 != -1 && num2 != -1) { double average = (num1 + num2) / 2.0; printf("%.1f ", average); num1 = num2; scanf("%d", &num2); } return 0; } Question2: #include <stdio.h> // Function to check if a number is prime int is_prime(int n) { if (n <= 1) { return 0; // Not prime } for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return 0; // Not prime } } return 1; // Prime } int main() { // Read the number of elements int N; scanf("%d", &N); // Read the list of numbers int ki; int prime_count = 0; // To keep track of the number of prime elements for (int i = 0; i < N; i++) { scanf("%d", &ki); // Check if the number is prime and print if it is if (is_prime(ki)) { if (prime_count > 0) { printf(" "); } printf("%d", ki); prime_count++; } } printf("\n"); // Add a newline at the end return 0; } Question3: #include <stdio.h> int findKthOdd(int k) { int num, count = 0; while (scanf("%d", &num) != EOF && num != -1) { if (num % 2 != 0) { count++; if (count == k) { return num; } } } return -1; // Less than k odd numbers in the sequence } int main() { int k; scanf("%d", &k); int result = findKthOdd(k); printf("%d", result); return 0; }
Subscribe to:
Post Comments (Atom)
April Week 2 || Lab 2 || Troubleshooting Data Models in Looker
CREATE NEW FILE NAME: user_order_lifetime view: user_order_lifetime { derived_table: { sql: SELECT order_items.user_id as us...
-
EXAM PREPARATION PDF PART 1 ABOUT THE COURSE : A fun filled whirlwind tour of 30 hrs, covering everything you need to know to fall in love w...
-
Exam Preparation PDF ABOUT THE COURSE : Industry 4.0 concerns the transformation of industrial processes through the integration of modern...
-
Exam Preparation PDF ABOUT THE COURSE : With the increased availability of data from varied sources there has been increasing attention paid...
No comments:
Post a Comment