Skip to content

Instantly share code, notes, and snippets.

View scratchyourbrain's full-sized avatar

scratchyourbrain

View GitHub Profile
import java.io.*;
import java.util.*;
class swap
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.print("Enter two numbers : ");
int m = s.nextInt();
@scratchyourbrain
scratchyourbrain / C program to Display Factors of a Number
Created December 31, 2014 05:16
C program to Display Factors of a Number
#include <stdio.h>
int main()
{
int n,i;
printf("Enter a positive integer: ");
scanf("%d",&n);
printf("Factors of %d are: ", n);
for(i=1;i<=n;++i)
{
if(n%i==0)
@scratchyourbrain
scratchyourbrain / C Program to Display Armstrong Number Between Two Intervals
Created December 24, 2014 07:30
C Program to Display Armstrong Number Between Two Intervals
#include <stdio.h>
int main()
{
int n1, n2, i, temp, num, rem;
printf("Enter two numbers(intervals): ");
scanf("%d %d", &n1, &n2);
printf("Armstrong numbers between %d an %d are: ", n1, n2);
for(i=n1+1; i<n2; ++i)
{
temp=i;
@scratchyourbrain
scratchyourbrain / C program to Check Armstrong Number
Created December 24, 2014 07:05
C program to Check Armstrong Number
#include <stdio.h>
int main()
{
int n, n1, rem, num=0;
printf("Enter a positive integer: ");
scanf("%d", &n);
n1=n;
while(n1!=0)
{
rem=n1%10;
@scratchyourbrain
scratchyourbrain / C Program to Display Prime Numbers Between Two Intervals
Created December 24, 2014 06:11
C Program to Display Prime Numbers Between Two Intervals
#include <stdio.h>
int main()
{
int n1, n2, i, j, flag;
printf("Enter two numbers(intevals): ");
scanf("%d %d", &n1, &n2);
printf("Prime numbers between %d and %d are: ", n1, n2);
for(i=n1+1; i<n2; ++i)
{
flag=0;
@scratchyourbrain
scratchyourbrain / C Program to Check Whether a Number is Prime or Not
Created December 24, 2014 05:39
C Program to Check Whether a Number is Prime or Not
#include <stdio.h>
int main()
{
int n, i, flag=0;
printf("Enter a positive integer: ");
scanf("%d",&n);
for(i=2;i<=n/2;++i)
{
if(n%i==0)
{
@scratchyourbrain
scratchyourbrain / C Program to Check Whether a Number is Palindrome or Not
Created December 21, 2014 14:26
C Program to Check Whether a Number is Palindrome or Not
#include <stdio.h>
int main()
{
int n, reverse=0, rem,temp;
printf("Enter an integer: ");
scanf("%d", &n);
temp=n;
while(temp!=0)
{
rem=temp%10;
@scratchyourbrain
scratchyourbrain / C program to Calculate the Power of a Number
Created December 19, 2014 09:57
C program to Calculate the Power of a Number
#include <stdio.h>
int main()
{
int base, exp;
long long int value=1;
printf("Enter base number and exponent respectively: ");
scanf("%d%d", &base, &exp);
while (exp!=0)
{
value*=base;
@scratchyourbrain
scratchyourbrain / C Program to Reverse a Number
Created December 19, 2014 09:40
C Program to Reverse a Number
#include <stdio.h>
int main()
{
int n, reverse=0, rem;
printf("Enter an integer: ");
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
@scratchyourbrain
scratchyourbrain / C Program to Count Number of Digits of an Integer
Created December 19, 2014 09:22
C Program to Count Number of Digits of an Integer
#include <stdio.h>
int main()
{
int n,count=0;
printf("Enter an integer: ");
scanf("%d", &n);
while(n!=0)
{
n/=10;
++count;