C Programming 2022 Solution New Syllabus
11.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include <stdio.h> // Function to find the greatest of three numbers int findGreatest(int num1, int num2, int num3) { if (num1 > num2 && num1 > num3) { return num1; } else if (num2 > num3) { return num2; } else { return num3; } } int main() { int num1, num2, num3; printf("Enter three numbers: "); scanf("%d %d %d", &num1, &num2, &num3); int greatest = findGreatest(num1, num2, num3); printf("The greatest number is: %d\n", greatest); return 0; } |
12.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <stdio.h> #include <string.h> int main() { char str[100]; // Assuming the maximum length of the string is 100 characters printf("Enter a string: "); scanf("%[^\n]", str); // Read the string with spaces until newline int length = strlen(str); printf("Length of the string: %d\n", length); return 0; } |
13. The main difference between a while loop and a do-while loop lies in when the loop condition is checked: While Loop: In a while loop, the condition is checked before the loop body is executed. If the condition is false initially, the loop body will not execute at all. […]
Continue Reading