# 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 convert given number of days into months and days

class Days { public static void main(String…s) { int n,m,d; n=Integer.parseInt(s[0]); m=n/30; d=n%30; System.out.println(n+” days“+” = “+m+” months “+”and “+d+” days”); } }

## 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); } }

## My First Java Program: Print a Message “Hello World”

class HelloWorld { public static void main(String…s) { System.out.println(“Hello World”); } }

## 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

Here you will get C program to calculate compound interest. The program asks user to enter value of principle (p), rate (r) and time (t) and finally calculates the compound interest by following formula. Compound Interest = Principle * (1 + Rate / 100) time C Program to Calculate Compound Interest

Output Enter Principle, Rate… Read More »

## 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 }