0% found this document useful (0 votes)
34 views8 pages

C Task

The document contains a collection of C programs that perform various tasks such as checking number properties, calculating areas, determining seasons, and evaluating grades. Each program includes user input, conditional statements, and outputs results based on the logic implemented. The programs cover a range of topics including arithmetic operations, geometric calculations, and character identification.

Uploaded by

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

C Task

The document contains a collection of C programs that perform various tasks such as checking number properties, calculating areas, determining seasons, and evaluating grades. Each program includes user input, conditional statements, and outputs results based on the logic implemented. The programs cover a range of topics including arithmetic operations, geometric calculations, and character identification.

Uploaded by

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

1 . #include <stdio.

h>

int main() {
int num;
scanf("%d", &num);

if (num > 0) {
if (num % 5 == 0) {
printf("Positive multiple of 5\n");
} else {
printf("Positive but not a multiple of 5\n");
}
}
else if (num < 0) {
if (num % 3 == 0) {
printf("Negative multiple of 3\n");
} else {
printf("Negative but not a multiple of 3\n");
}
}
else {
printf("The number is zero\n");
}

return 0;
}
------------------------------------------------------------
2.#include <stdio.h>

int main() {
int x, y;
printf("Enter x coordinate: ");
scanf("%d", &x);
printf("Enter y coordinate: ");
scanf("%d", &y);

if (x == 0 && y == 0) {
printf("Origin\n");
}
else if (x == 0) {
printf("Point lies on the Y-axis\n");
}
else if (y == 0) {
printf("Point lies on the X-axis\n");
}
else if (x > 0 && y > 0) {
printf("Quadrant I\n");
}
else if (x < 0 && y > 0) {
printf("Quadrant II\n");
}
else if (x < 0 && y < 0) {
printf("Quadrant III\n");
}
else {
printf("Quadrant IV\n");
}

return 0;
}

----------------------------------------------------------------
3. Electricity Bill Calculator

#include <stdio.h>

int main() {
int units;
float bill = 0;
scanf("%d", &units);

if (units <= 100) {


bill = units * 0.50;
} else if (units <= 200) {
bill = 100 * 0.50 + (units - 100) * 0.75;
} else if (units <= 300) {
bill = 100 * 0.50 + 100 * 0.75 + (units - 200) * 1.20;
} else {
bill = 100 * 0.50 + 100 * 0.75 + 100 * 1.20 + (units - 300) * 1.50;
}

printf("Total bill: $%.2f\n", bill);


return 0;
}
---------------------------------------------------------------
4. Simple Calculator with Switch

#include <stdio.h>

int main() {
int a, b;
char op;

printf("Enter two integers: ");


scanf("%d %d", &a, &b);

printf("Enter operator (+, -, *, /): ");


scanf(" %c", &op);

switch (op) {
case '+':
printf("Result: %d\n", a + b);
break;
case '-':
printf("Result: %d\n", a - b);
break;
case '*':
printf("Result: %d\n", a * b);
break;
case '/':
if (b == 0) {
printf("Division by zero is not allowed.\n");
} else {
printf("Result: %d\n", a / b);
}
break;
default:
printf("Invalid operator.\n");
}

return 0;
}
---------------------------------------------------------------
5. Area Calculator using Switch
#include <stdio.h>
#include <math.h>

int main() {
char shape;
float area;
scanf(" %c", &shape);

switch (shape) {
case 'C': {
float r;
scanf("%f", &r);
area = M_PI * r * r;
printf("Area of Circle = %.2f\n", area);
break;
}
case 'S': {
float side;
scanf("%f", &side);
area = side * side;
printf("Area of Square = %.2f\n", area);
break;
}
case 'R': {
float l, w;
scanf("%f %f", &l, &w);
area = l * w;
printf("Area of Rectangle = %.2f\n", area);
break;
}
case 'T': {
float b, h;
scanf("%f %f", &b, &h);
area = 0.5 * b * h;
printf("Area of Triangle = %.2f\n", area);
break;
}
default:
printf("Invalid shape\n");
}

return 0;
}
-----------------------------------------------------------------------------------
----
6. Triangle Classification
#include <stdio.h>

int main() {
int a, b, c;

printf("Enter three sides of the triangle: ");


scanf("%d %d %d", &a, &b, &c);
if (a + b > c && a + c > b && b + c > a) {
if (a == b && b == c) {
printf("The triangle is Equilateral.\n");
} else if (a == b || b == c || a == c) {
printf("The triangle is Isosceles.\n");
} else {
printf("The triangle is Scalene.\n");
}
} else {
printf("The given lengths do not form a valid triangle.\n");
}

return 0;
}
-----------------------------------------------------------------------------------
7. Student Attendance Calculator
#include <stdio.h>

int main() {
char name[50];
int roll, total_days, present_days;
float percentage;

printf("Enter student name: ");


scanf(" %[^\n]", name);
printf("Enter roll number: ");
scanf("%d", &roll);
printf("Enter total number of working days: ");
scanf("%d", &total_days);
printf("Enter total number of days present: ");
scanf("%d", &present_days);

percentage = (present_days * 100.0) / total_days;

printf("Attendance percentage: %.0f%%\n", percentage);

return 0;
}
-----------------------------------------------------------------------------------
-
8. Vowel or Consonant Checker
#include <stdio.h>
#include <ctype.h>

int main() {
char ch;
printf("Enter a character: ");
scanf(" %c", &ch);

if (!isalpha(ch)) {
printf("Invalid input\n");
} else {
ch = tolower(ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
printf("Vowel\n");
else
printf("Consonant\n");
}
return 0;
}
--------------------------------------------------------------------------------
9. Leap Year Checker
#include <stdio.h>

int main() {
int year;
scanf("%d", &year);

if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))


printf("%d is a Leap Year\n", year);
else
printf("%d is not a Leap Year\n", year);

return 0;
}
-------------------------------------------------------------------------------
10. Divisibility by 4 and 6
#include <stdio.h>

int main() {
int num;
scanf("%d", &num);

if (num % 4 == 0 && num % 6 == 0)


printf("The number is divisible by both 4 and 6.\n");
else if (num % 4 == 0)
printf("The number is divisible by 4 but not by 6.\n");
else if (num % 6 == 0)
printf("The number is divisible by 6 but not by 4.\n");
else
printf("The number is not divisible by 4 or 6.\n");

return 0;
}
------------------------------------------------------------------
11. FizzBuzz
#include <stdio.h>

int main() {
int num;
scanf("%d", &num);

if (num % 3 == 0 && num % 5 == 0)


printf("FizzBuzz\n");
else if (num % 3 == 0)
printf("Fizz\n");
else if (num % 5 == 0)
printf("Buzz\n");
else
printf("%d\n", num);

return 0;
}
------------------------------------------------------------------------------
12. Season Determiner
#include <stdio.h>
int main() {
int month;
printf("Enter month (1-12): ");
scanf("%d", &month);

switch (month) {
case 12:
case 1:
case 2:
printf("Winter\n");
break;
case 3:
case 4:
case 5:
printf("Spring\n");
break;
case 6:
case 7:
case 8:
printf("Summer\n");
break;
case 9:
case 10:
case 11:
printf("Fall\n");
break;
default:
printf("Invalid month\n");
}

return 0;
}
------------------------------------------------------------------------------
13. Convert Minutes to Hours and Minutes
#include <stdio.h>

int main() {
int totalMinutes, hours, minutes;

printf("Enter total minutes: ");


scanf("%d", &totalMinutes);

hours = totalMinutes / 60;


minutes = totalMinutes % 60;

printf("%d hour(s) and %d minute(s)\n", hours, minutes);

return 0;
}
-----------------------------------------------------------------------------------
14. Profit or Loss Calculator
#include <stdio.h>

int main() {
int costPrice, sellingPrice, diff;
scanf("%d", &costPrice);
scanf("%d", &sellingPrice);
diff = sellingPrice - costPrice;

if (diff > 0) {
printf("Profit : %d\n", diff);
}
else if (diff < 0) {
printf("Loss : %d\n", -diff);
}
else {
printf("No profit, no loss\n");
}

return 0;
}
----------------------------------------------------------------------------------
15. Vehicle Speed Check
#include <stdio.h>

int main() {
int speed, limit;
scanf("%d", &speed);
scanf("%d", &limit);

if (speed > limit) {


printf("Warning: Speeding!\n");
}
else {
printf("OK: Within Speed Limit\n");
}

return 0;
}
---------------------------------------------------------------------------
16. Festival Discount
#include <stdio.h>

int main() {
float price, discount, finalPrice;
scanf("%f", &price);
scanf("%f", &discount);

finalPrice = price - (price * discount / 100);

printf("Final Price = %.2f\n", finalPrice);

return 0;
}
--------------------------------------------------------------------------
17. Grade Evaluator
#include <stdio.h>

int main() {
int score;

scanf("%d", &score);

if (score >= 90) {


printf("Grade: A\n");
}
else if (score >= 80) {
printf("Grade: B\n");
}
else if (score >= 70) {
printf("Grade: C\n");
}
else if (score >= 60) {
printf("Grade: D\n");
}
else {
printf("Grade: F\n");
}

return 0;
}
-----------------------------------------------------------------------------
18. Character Identifier
#include <stdio.h>
#include <ctype.h>

int main() {
char ch;

scanf(" %c", &ch);

if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
printf("Alphabet\n");
}
else if (ch >= '0' && ch <= '9') {
printf("Digit\n");
}
else {
printf("Special Character\n");
}

return 0;
}
------------------------------------------------------------------------------
19. Buzz Number Check

#include <stdio.h>

int main() {
int num;
scanf("%d", &num);

if (num % 7 == 0 || num % 10 == 7) {
printf("%d is a Buzz Number\n", num);
}
else {
printf("%d is NOT a Buzz Number\n", num);
}

return 0;
}

You might also like