1.
```c
include
int main() {
int num1, num2, sum;
printf("Enter first integer: ");
scanf("%d", &num1);
printf("Enter second integer: ");
scanf("%d", &num2);
sum = num1 num2;
printf("Sum: %d\n", sum);
return 0;
}
```
2.
```c
include
int main() {
int num, factorial = 1;
printf("Enter an integer: ");
scanf("%d", &num);
if (num < 0) {
printf("Error: Factorial of negative number is undefined.\n");
return 1;
}
for (int i = 1; i <= num; i) {
factorial *= i;
}
printf("Factorial of %d is: %d\n", num, factorial);
return 0;
}
```
3.
```c
include
define SIZE 10
int main() {
int arr[SIZE] = {10, 5, 8, 20, 15, 3, 12, 18, 7, 25};
int max_index = 0, min_index = 0;
for (int i = 1; i < SIZE; i) {
if (arr[i] > arr[max_index])
max_index = i;
if (arr[i] < arr[min_index])
min_index = i;
}
printf("Maximum value %d found at index %d.\n", arr[max_index], max_index);
printf("Minimum value %d found at index %d.\n", arr[min_index], min_index);
return 0;
}
```
这些题目涵盖了基本的输入输出、条件语句、循环语句和数组操作。希望它们对你有帮助!
文章已关闭评论!
2025-04-05 00:34:15
2025-04-05 00:16:17
2025-04-04 23:58:13
2025-04-04 23:40:14
2025-04-04 23:22:06
2025-04-04 23:04:06
2025-04-04 22:45:45
2025-04-04 22:27:40