Showing posts with label numbers. Show all posts
Showing posts with label numbers. Show all posts

Saturday, March 10, 2012

Write a C program to check whether a given number is palindrome or not.

#include 
#include 
void main()
{
 long int n, num, rev = 0, dig;
 printf("\n Enter a number...: ");
scanf("%ld", &num);
 n = num;
while(num>0)
{
dig = num % 10;
 rev = rev * 10 + dig;
 num = num / 10;
 }
 if (n == rev)
 printf("\nGiven number is a palindrome");
 else
 printf("\n Given number not a palindrome");
 getch();
}

Write a program to check whether a given number is armstrong or not.




#include  
#include  
void main()
{
 int a,b,y,m,q;
printf(“Enter any no. \n”);
scanf(“%d”,&a);
 b=a;
y=0;
while(b!=0)
{
 m=b%10;
 q=b/10;
 y=y+(m*m*m);
 b=q;
}
if(y==a)
{
printf(“ The no. is Armstrong\n”); printf("%d\n",a);
}
else
{


printf(“ The no. is not Armstrong\n”); printf("%d\n",a);
}
getch();

}

Write a C program to find prime numbers from 1 to n.

#include
#include
void main()
{
int i,j,n;
clrscr();
printf("Enter the no: ");
scanf("%d",&n);
printf("\n");
for(i=1;i<=n;i++)
{
for(j=2;j<=i-1;j++)
{
if(i%j==0)
break;
}
if(j==i)
printf("%d ",j);
}
getch();
}

Write a C program to find the sum of first n natural numbers.

#include  
#include
void main()
{
 int i, n, sum = 0;
clrscr();
printf(“Enter an integer number\n”);
scanf (“%d”, &n);
for (i=1; i <= n; i++)
{
 sum = sum + i;
}
printf (“Sum of first %d natural numbers = %d\n”, n, sum);

getch();
}

Write a program to find the factorial of a number using loop.

#include
#include
void main()
{
int a,b,fact=1;
clrscr();
printf("Enter number to find factorial");
scanf("%d",&b);
for(a=b;a>0;a--)
{
fact=fact*a;
}
printf("%d ",fact);
getch();
}

Write a C program to find the factorial of a number using recursion.

#include
#include
int fact(int);
void main()
{
int num,fact1;
printf("Enter a value of num");
scanf("%d",&num);
fact1=fact(num);
printf("factorial=%d",fact1);
getch();
}
int fact(int n)
{
int f=1;
if(n==0)
{
return 1;
}
else
{
f=n*fact(n-1);
return(f);
}
}

Tuesday, February 22, 2011

Write a Visual Basic Program to find the greatest among three numbers

WAP to find the greatest among three numbers.
_________________________________________

Private Sub Command1_Click()
Dim a
a = Val(Text1.Text)

If Text1.Text = "" Then
Label2.Caption = "ENTER ANY INTERGER"
ElseIf a Mod 2 = 0 Then
Label2.Caption = "Even Number"
Else
Label2.Caption = "Odd Number"
End If
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Label2.Caption = ""
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Form_Load()

End Sub

_______________________________________
OUTPUT
_______________________________________


____________________________________
DOWNLOAD
____________________________________

Download its form

Download its Image



Write a Visual Basic Program for displaying all prime numbers below 10000

WAP for displaying all prime numbers .
______________________________________

Dim a

Private Sub clear_cmd_Click()
List1.Clear

End Sub

Private Sub exit_cmd_Click()
End
End Sub

Private Sub Form_Load()

End Sub

Private Sub generate_cmd_Click()
List1.Clear
a = Val(Text1.Text)
For i = 2 To a Step 1
For j = 2 To i Step 1
If i Mod j = 0 Then
GoTo S
ElseIf j + 1 = i Then
a = i
List1.AddItem (a)
End If
Next j
S:
Next i




End Sub


_______________________________________
OUTPUT
_______________________________________


____________________________________
DOWNLOAD
____________________________________

Download its form

Download its Image