Text Practice Mode
C Programming
created Oct 1st, 09:14 by khr1st
1
283 words
1 completed
0
Rating visible after 3 or more votes
00:00
#include <stdio.h> int main() { int arraySize = 100; int numbers[arraySize]; for (int i = 0; i < arraySize; i++) { numbers[i] = i * 2; } int calculateSum(int arr[], int size) { int sum = 0; for (int j = 0; j < size; j++) { sum += arr[j]; } return sum; } int total = calculateSum(numbers, arraySize); printf("The sum of the first %d even numbers is: %d\n", arraySize, total); if (total > 1000) { printf("The sum exceeds 1000, which is quite large!\n"); } else { printf("The sum is within the acceptable range.\n"); } int *ptr = numbers; for (int k = 0; k < arraySize; k++) { printf("Element %d: %d\n", k, *(ptr + k)); } int factorial(int n) { if (n == 0) return 1; return n * factorial(n - 1); } printf("Factorial of 5 is: %d\n", factorial(5)); char name[50]; printf("Enter your name: "); scanf("%s", name); printf("Hello, %s!\n", name); double areaOfCircle(double radius) { return 3.14159 * radius * radius; } double radius; printf("Enter the radius of the circle: "); scanf("%lf", &radius); printf("The area of the circle is: %.2f\n", areaOfCircle(radius)); int fibonacci(int n) { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); } int fibNumber; printf("Enter a number to find its Fibonacci: "); scanf("%d", &fibNumber); printf("Fibonacci of %d is: %d\n", fibNumber, fibonacci(fibNumber)); for (int m = 0; m < 5; m++) { printf("This is loop iteration %d\n", m + 1); } printf("Demonstrating a switch statement:\n"); int choice; printf("Enter a number (1-3): "); scanf("%d", &choice); switch (choice) { case 1: printf("You selected option 1\n"); break; case 2: printf("You selected option 2\n"); break; case 3: printf("You selected option 3\n"); break; default: printf("Invalid selection\n"); break; } return 0; }
saving score / loading statistics ...