-->

Facebook

Jasper Roberts - Blog

Tuesday, March 31, 2015

Write a C Program to Add, subtract and multiply two nos. using switch statement.



PRACTICAL-SET-4
3.  Add, subtract and multiply two nos. using switch statement.


#include<stdio.h>
#include<stdio.h>

void main()
{
int num1,num2, choice;
clrscr();

printf("Enter the value of number1 : ");
scanf("%d",&num1);

printf("Enter the value of number2 : ");
scanf("%d",&num2);


printf("\n 1. Addition, ");
printf("\n 2. Substraction,");
printf("\n 3. Multiplication,  ");
printf("\n 4. Division.");

printf("\n Enter Your Choice:");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("%d + %d = %d",num1, num2, num1+num2);
break;

case 2:
printf("%d - %d = %d",num1, num2, num1-num2);
break;

case 3:
printf("%d * %d = %d",num1, num2, num1*num2);
break;
case 4:
printf("%d / %d = %d",num1, num2, num1/num2);
break;

default:
printf("Please enter the correct choise!!");
}
getch();

}

OUTPUT:
Enter the value of number1 : 10
Enter the value of number2 : 10
 1. Addition,
 2. Substraction,
 3. Multiplication,
 4. Division.

Enter Your Choice:1
10 + 10 = 20

Write a c program to reverse the digit.

PRACTICAL-SET-
2.  Write a prograto reverse the digit.


#include<stdio.h>
#include<conio.h>

void main()
{
    int num,r,reverse=0;
    clrscr();

    printf("Enter the number: ");
    scanf("%d",&num);

    while(num)
{
         r=num%10;
         reverse=reverse*10+r;
         num=num/10;
    }

    printf("Reverse of a given number is = %d",reverse);
getch();
}

OUTPUT:
Enter the number:  1234
Reverse of a given number is = 4321