We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Check if a number is even or odd: {
#include <stdio.h> printf("%d is zero.\n", num);
} int main() return 0; { } int num; printf("Enter an integer: "); Check if a student passed or failed based scanf("%d", &num); on marks: if (num % 2 == 0) #include <stdio.h> { int main() printf("%d is even.\n", num); { } int marks; else printf("Enter the marks: "); { scanf("%d", &marks); printf("%d is odd.\n", num); if (marks >= 40) } { printf("Congratulations! You passed.\n"); return 0; } else } { Compare two numbers and find the printf("Sorry! You failed.\n"); } maximum: return 0; #include <stdio.h> } int main() { int num1, num2; Find the largest of three numbers: printf("Enter two integers: "); #include <stdio.h> scanf("%d %d", &num1, &num2); int main() if (num1 > num2) { { int num1, num2, num3; printf("%d is the maximum.\n", num1); printf("Enter three numbers: "); } scanf("%d %d %d", &num1, &num2, &num3); else if (num1 >= num2 && num1 >= num3) { { printf("%d is the maximum.\n", num2); printf("%d is the largest.\n", num1); } } else if (num2 >= num1 && num2 >= num3) { return 0; printf("%d is the largest.\n", num2); } } else { Check if a number is positive, negative, printf("%d is the largest.\n", num3); or zero: } #include <stdio.h> int main() return 0; { } int num; printf("Enter an integer: "); scanf("%d", &num); if (num > 0) { printf("%d is positive.\n", num); } else if (num < 0) { printf("%d is negative.\n", num); } else