0% found this document useful (0 votes)
14 views15 pages

Assignment 4 Word

The document contains 10 programming assignments involving conditional statements in C language. The assignments include programs to determine the day of the week from a number input, a basic calculator using switch case, checking if a year is a leap year, checking if a character is an alphabet, swapping two numbers with and without a temporary variable, displaying the rightmost digit of a number, checking if a number is odd or even, checking if a number is positive, negative or zero, determining the type of triangle, and converting inches to centimeters. Source code and output are provided for each assignment.

Uploaded by

Jeet
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)
14 views15 pages

Assignment 4 Word

The document contains 10 programming assignments involving conditional statements in C language. The assignments include programs to determine the day of the week from a number input, a basic calculator using switch case, checking if a year is a leap year, checking if a character is an alphabet, swapping two numbers with and without a temporary variable, displaying the rightmost digit of a number, checking if a number is odd or even, checking if a number is positive, negative or zero, determining the type of triangle, and converting inches to centimeters. Source code and output are provided for each assignment.

Uploaded by

Jeet
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/ 15

Assignment 4:

Conditional
Statements

NAME : JEET ARIWALA


ROLL NO. : A-69
1. Write a program that reads a number between 1 to 7 from the
user and display the day of the week from Monday to Sunday.

SOURCE CODE :

#include<stdio.h>
#include<conio.h>
int main()
{
int days; //using switch operator
printf("1) Monday\t");
printf("2) Tuesday\t");
printf("3) Wednesday\t");
printf("4) Thursday\n");
printf("5) Friday\t");
printf("6) Saturday\t");
printf("7) Sunday\n");
printf("Please enter a value:"); //between 1-7
scanf("%d",&days);

switch(days)
{
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
case 7:
printf("Sunday\n");
break;
default:
printf("INVALID:Please enter value between 1-7\n");
break;
}
getch();
}

OUTPUT:

2. Make a simple calculator using a simple switch case.

SOURCE CODE:

#include<stdio.h>
#include<conio.h>
int main()
{
float num1,num2,add,sub,mul,div; //basic calculator
char x;
printf("WELCOME TO MY SIMPLE CALCULATOR\n");
printf("Enter your num1:");
scanf("%f",&num1);
printf("Enter your num2:");
scanf("%f",&num2);

add=num1+num2;
sub=num1-num2;
mul=num1*num2;
div=num1/num2;

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


scanf("%s",&x);

switch(x)
{
case '+':
{
printf("\nYour choice is addition\n");
printf("Your addition of num1 and num2 is %f",add);
break;
}
case '-':
{
printf("Your choice is substraction\n");
printf("Your substraction of num1 and num2 is
%f",sub);
break;
}
case '*':
{
printf("Your choice is multiplication\n");
printf("Your multiplication of num1 and num2 is
%f",mul);
break;
}
case '/':
{
printf("Your choice is division\n");
printf("Your division of num1 and num2 is %f",div);
break;
}
default:
{ printf("Your choice is invalid.\n");
printf("Please choose a correct operand.");
break;
}
}
getch();
}

OUTPUT:
3. Write a program to check whether the given year is a leap year
or not.

SOURCE CODE :
OUTPUT:
4. Write a program to check whether a character is an alphabet or
not.

SOURCE CODE:

OUTPUT:
5. Write a program to swap two numbers with and without using
a temporary variable.

(i) WITH TEMP

SOURCE CODE:

OUTPUT:

(ii) WITHOUT TEMP


SOURCE CODE:

OUTPUT:

6. Write a program to read a floating-point number display the


rightmost digit of an integral part of the number.

SOURCE CODE:
OUTPUT:

7. Write a program to check whether the number is odd or even.

SOURCE CODE:
OUTPUT:

8. Write a program to check whether the number is positive or


negative or zero.

SOURCE CODE:
OUTPUT:
9. Write a program to check whether the triangle is equilateral,
isosceles or scalene triangle.

SOURCE CODE:

OUTPUT:
10. Write a program that takes distance in inches and prints the
corresponding value in cms. (Note that 1 inch = 2.54 cm)

SOURCE CODE:

OUTPUT:

You might also like