Category Archives: Simple

How to Swap Two Numbers Without Using Temporary Variable or Arithmetic Operators?

You have done swapping of two numbers using temporary variable or by using arithmetic operators. It can be done in following way. Lets take two numbers a=5 and b=7. Using Temporary Variable temp=a;            //temp becomes 5 a=b;                 //a becomes 7 b=temp;            //b becomes 5 Also Read: C++ program to swap two numbers using pointers Also Read: C++… Read More »

Java program to swap two numbers without using temp variable

class Swap { public static void main(String…s) { int a,b; a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); System.out.println(“nBefore Swap:n”+”a=”+a+”tb=”+b); a=a+b; b=a-b; a=a-b; System.out.println(“nAfter Swap:n”+”a=”+a+”tb=”+b); } }

Java program to swap two numbers

class Swap { public static void main(String…s) { int a,b,temp; a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); System.out.println(“nBefore Swap:n”+”a=”+a+”tb=”+b); temp=a; a=b; b=temp; System.out.println(“nAfter Swap:n”+”a=”+a+”tb=”+b); } }

C++ program to find cube of a number using macros

Also Read: C++ program to swap two numbers using macros Also Read: C++ Program to find cube of a number using function #include<iostream.h> #include<conio.h> #define CUBE(x) (x*x*x) void main() { clrscr(); int n,cube; cout<<“Enter a number:”; cin>>n; cube=CUBE(n); cout<<“Cube=”<<cube; getch(); }

C program to print size of different data types

#include<stdio.h> #include<conio.h> void main() { clrscr(); printf(“TypettttSize (bytes)”); printf(“nCharacterttt    %d”,sizeof(char)); printf(“nIntegertttt    %d”,sizeof(int)); printf(“nLong intttt    %d”,sizeof(long int)); printf(“nFloattttt    %d”,sizeof(float)); printf(“nDoubletttt    %d”,sizeof(double)); printf(“nLong doublettt    %d”,sizeof(long double)); getch(); }

C++ program to swap two numbers using macros

#include<iostream.h> #include<conio.h> #define SWAP(a,b) {int temp; temp=a; a=b; b=temp;} void main() { clrscr(); int x,y; cout<<“Enter two numbers:”; cin>>x>>y; cout<<“x=”<<x<<” y=”<<y; SWAP(x,y); cout<<“nx=”<<x<<” y=”<<y; getch(); }

C++ Program to Add Two Numbers

Here you will get C++ program to add two numbers. The program will ask user to enter two numbers and then calculate their sum.

Output Enter first no: 4 Enter second no: 6 Sum = 10

C program to calculate compound interest

#include<stdio.h> #include<conio.h> #include<math.h> void main() { float p,r,t,ci; clrscr(); printf(“Enter Principle, Rate and Time: “); scanf(“%f%f%f”,&p,&r,&t); ci=pow(p*(1+r/100),t); printf(“Bank Loans Compound Interest = %f%”,ci); getch(); }

C program to calculate simple interest

#include<stdio.h> #include<conio.h> void main() { float p,r,t,si; clrscr(); //to clear the screen printf(“Enter principal,rate and time;”); scanf(“%f%f%f”,&p,&r,&t); si=(p*r*t)/100; printf(“nSI=%f”,si); getch(); //to stop the screen }

C program to raise any number x to a positive power n

#include<stdio.h> #include<conio.h> #include<math.h> void main() { int x,n,result; clrscr(); //to clear the scrren printf(“Enter value of x and n:”); scanf(“%d%d”,&x,&n); result=pow(x,n); printf(“nResult=%d”,result); getch(); //to stop the screen }