0% found this document useful (0 votes)
6 views3 pages

PCA1 C Programming Solutions

The document provides C programming solutions for eight different tasks, including basic arithmetic operations, temperature conversion, area calculation, and number comparisons. It also includes examples of control structures such as if-else statements and switch cases. Each solution is presented with sample code and comments for clarity.

Uploaded by

sarimdawar02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

PCA1 C Programming Solutions

The document provides C programming solutions for eight different tasks, including basic arithmetic operations, temperature conversion, area calculation, and number comparisons. It also includes examples of control structures such as if-else statements and switch cases. Each solution is presented with sample code and comments for clarity.

Uploaded by

sarimdawar02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PCA-1 (Any Eight) - C Programming Solutions

1. Addition and Subtraction of Two Numbers


#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
printf("Addition = %d\n", a + b);
printf("Subtraction = %d\n", a - b);
return 0;
}

2. Convert Fahrenheit to Celsius


#include <stdio.h>
int main() {
float f, c;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &f);
c = (f - 32) * 5 / 9;
printf("Temperature in Celsius = %.2f\n", c);
return 0;
}

3. Area of a Rectangle
#include <stdio.h>
int main() {
float l, b, area;
printf("Enter length and breadth: ");
scanf("%f%f", &l, &b);
area = l * b;
printf("Area of rectangle = %.2f\n", area);
return 0;
}

4. Check Even or Odd Using if-else


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

5. Find Bigger of Two Numbers


#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
if (a > b)
printf("%d is bigger\n", a);
else
printf("%d is bigger\n", b);
return 0;
}

6. Biggest of Three Numbers using Nested if-else


#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three numbers: ");
scanf("%d%d%d", &a, &b, &c);
if (a > b) {
if (a > c)
printf("%d is biggest\n", a);
else
printf("%d is biggest\n", c);
} else {
if (b > c)
printf("%d is biggest\n", b);
else
printf("%d is biggest\n", c);
}
return 0;
}

7. Display Grade using else-if


#include <stdio.h>
int main() {
int marks;
printf("Enter marks: ");
scanf("%d", &marks);
if (marks >= 90)
printf("Grade A\n");
else if (marks >= 80)
printf("Grade B\n");
else if (marks >= 70)
printf("Grade C\n");
else if (marks >= 60)
printf("Grade D\n");
else
printf("Grade F\n");
return 0;
}

8. Calculator using Switch


#include <stdio.h>
int main() {
int a, b, choice;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
printf("1. Add\n2. Subtract\n3. Multiply\nEnter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: printf("Result = %d\n", a + b); break;
case 2: printf("Result = %d\n", a - b); break;
case 3: printf("Result = %d\n", a * b); break;
default: printf("Invalid choice\n");
}
return 0;
}

9. Print 1 to 100 using For Loop


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

You might also like