0% found this document useful (0 votes)
16 views6 pages

Assignment 5

The document contains multiple C programming assignments that include checking if a character is an alphabet, digit, or special character; determining if a year is a leap year; checking if a number is even or odd; identifying colors based on input codes using switch-case statements; and creating a simple calculator using switch-case for basic arithmetic operations. Each assignment includes the necessary code snippets and prompts for user input. The programs demonstrate fundamental programming concepts such as conditionals, loops, and user input handling.

Uploaded by

Priyanka rani
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)
16 views6 pages

Assignment 5

The document contains multiple C programming assignments that include checking if a character is an alphabet, digit, or special character; determining if a year is a leap year; checking if a number is even or odd; identifying colors based on input codes using switch-case statements; and creating a simple calculator using switch-case for basic arithmetic operations. Each assignment includes the necessary code snippets and prompts for user input. The programs demonstrate fundamental programming concepts such as conditionals, loops, and user input handling.

Uploaded by

Priyanka rani
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
You are on page 1/ 6

ASSIGNMENT 5

1. Write a program to check if


character enters by user is an
alphabet, digit or special
character.
2. #include<stdio.h>
3.
4. int main()
5. {
6. char ch;
7. printf("enter your character\n");
8.
9. scanf("%c",&ch);
10. printf("%c\n", ch);
11. if ((ch>='a')&&(ch<='z')||(ch>='A')&& (ch<='Z')){
12. printf("it's an alphabet charcter ");
13. }
14. else if( ch>='0'&&ch<='9'){
15. printf("it's a digit charcter");
16. }
17. else{
18. printf("special character");
19. }
20. return 0;
21. }

2. Write a program to take an year as input and check if it is


leap or not.
#include <stdio.h>

int main()
{
int year;
printf("enter current year\n");
scanf("%d", &year);

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


{
printf("leap year!");
}
else{
printf("not a leap year");
}

return 0;
}

3. Write a program to take a number as input and check if it is even or odd.


#include <stdio.h>

int main()
{
int number;
printf("enter your number\n");
scanf("%d", &number);

if (number%2==0)
{
printf("even number!");
}
else{
printf("odd number");
}

return 0;
}

4.Write a program to take color code as input from user and


print the name of the color corresponding to it. Use switch-
case statement. (R-> Red , G-> Green, W-> White, P-> Pink, B-
> Blue)
#include<stdio.h>

int main()

char color;

printf("enter your color code\n");


scanf("%c",&color);

switch (color)

case 'R':

printf("the color is red\n");

break;

case 'G':

printf("the color is green\n");

break;

case 'W':

printf("COLOR IS WHITE\n");

break;

case 'P':

printf("COLOR IS PINK\n");

break;

case'B':

printf("COLOR IS BLUE\n");

break;

default:

printf("ANY OTHER COLOUR\n");

return 0;

}
5 MAKE A CALCULATOR USING SWITCH CASE

#include <stdio.h>

int main()
{
int number, a, b;
printf("enter your first number\n");
scanf("%d", &a);
printf("enter your second number\n");
scanf("%d", &b);
char ch;
printf("enter your character\n");
scanf("\n%c", &ch);

switch (ch)
{
case '+':
printf("sum is %d", a + b);
break;
case '-':
printf("subtraction is %d", a - b);
break;
case '*':
printf("multiplication is %d", a * b);
break;

case '/':
printf("division is %f", (float)a / b);
break;

default:
printf("no such operator\n");
}
return 0;
}

You might also like