0% found this document useful (0 votes)
5 views4 pages

C Programming Solutions

The document contains C programming solutions for various problems, including calculating an equation result, finding the biggest number, determining if a number is odd or even, checking for prime numbers, and more. Each solution is presented as a complete C program with input and output functionality. The problems range from basic arithmetic and conditional statements to loops and mathematical functions.

Uploaded by

hanymina682
Copyright
© All Rights Reserved
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
0% found this document useful (0 votes)
5 views4 pages

C Programming Solutions

The document contains C programming solutions for various problems, including calculating an equation result, finding the biggest number, determining if a number is odd or even, checking for prime numbers, and more. Each solution is presented as a complete C program with input and output functionality. The problems range from basic arithmetic and conditional statements to loops and mathematical functions.

Uploaded by

hanymina682
Copyright
© All Rights Reserved
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

C Programming – Solutions

1. Equation Result

#include <stdio.h>
int main() {
int num1, num2;
float result;
scanf("%d %d", &num1, &num2);
result = ((num1 + num2) * 3) / 2.0 - 10;
printf("Result = %.2f", result);
return 0;
}

2. Biggest Number

#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
if (a > b)
printf("Biggest = %d", a);
else if (b > a)
printf("Biggest = %d", b);
else
printf("Numbers are equal");
return 0;
}

3. Odd or Even

#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
if (n % 2 == 0)
printf("Even");
else
printf("Odd");
return 0;
}

4. Prime or Not

#include <stdio.h>
int main() {
int n, i, prime = 1;
scanf("%d", &n);
if (n <= 1) prime = 0;
for (i = 2; i <= n/2; i++) {
if (n % i == 0) {
prime = 0;
break;
}
}
if (prime)
printf("Prime");
else
printf("Not Prime");
return 0;
}

5. Power of 2

#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
if (n > 0 && (n & (n - 1)) == 0)
printf("Yes");
else
printf("No");
return 0;
}

6. Factorial

#include <stdio.h>
int main() {
int n, i;
long long fact = 1;
scanf("%d", &n);
for (i = 1; i <= n; i++)
fact *= i;
printf("%lld", fact);
return 0;
}

7. Perfect Square

#include <stdio.h>
#include <math.h>
int main() {
int n, r;
scanf("%d", &n);
r = sqrt(n);
if (r * r == n)
printf("Perfect Square");
else
printf("Not Perfect Square");
return 0;
}

8. Student Grade

#include <stdio.h>
int main() {
int g;
scanf("%d", &g);
if (g >= 85) printf("Excellent");
else if (g >= 75) printf("Very Good");
else if (g >= 65) printf("Good");
else if (g >= 50) printf("Pass");
else printf("Fail");
return 0;
}

9. Prime Numbers from 1 to 100

#include <stdio.h>
int main() {
int i, j, prime;
for (i = 2; i <= 100; i++) {
prime = 1;
for (j = 2; j <= i/2; j++) {
if (i % j == 0) {
prime = 0;
break;
}
}
if (prime)
printf("%d ", i);
}
return 0;
}

You might also like