Write a program in C or C++ to perform all arithmetic operation (Using two variables) that is subtraction(-), addition(+), division(/), multiplication(*) & modulus(%) with Output
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,g
clrscr();
printf ("Enter first number\n");
scanf ("%d", &a);
printf("Enter second number");
scanf ("%d", &b);
c=a+b;
printf("Addition is :%d", c);
d=a-b;
printf("Subtraction is :%d", d);
e=a*b;
printf("Multiplication is :%d", e);
f=a/b;
printf("Division is:%d ", f);
g=a%b;
printf("/n"Mod is : %d ", g);
getch();
}
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
Click here to check the output
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,g
clrscr();
printf ("Enter first number\n");
scanf ("%d", &a);
printf("Enter second number");
scanf ("%d", &b);
c=a+b;
printf("Addition is :%d", c);
d=a-b;
printf("Subtraction is :%d", d);
e=a*b;
printf("Multiplication is :%d", e);
f=a/b;
printf("Division is:%d ", f);
g=a%b;
printf("/n"Mod is : %d ", g);
getch();
}
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
Click here to check the output
No comments:
Post a Comment