Showing posts with label study. Show all posts
Showing posts with label study. Show all posts

Saturday, March 10, 2012

C Programs Lists With their output

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 program to find fibonacci series in c using loop.

#include
#include
void fiab(int n)
{
int a=0,b=1,add=0;
printf("%d %d ",a,b);
while(add
{
add=a+b;
a=b;
b=add;
printf("%d ",a);
}
}

void main()
{
int i,j,a,b;
clrscr();
printf("\n Enter number to print fibonacci number:\n");
scanf("%d",&a);
printf("\n Fiabonacci series:\n");
fiab(a);
getch();
}

Write a program to find fibonacci series in c using recursion.

#include
#include
int fiab(int);

void main()
{
int i,n;
clrscr();
printf("How many terms do you wish to find?\n");
scanf("%d",&n);

printf("\nThe Series is : \n");

for(i=1;i<=n;i++)
{
printf(" %d \n",fiab(i));
}

getch();
}

int fiab(int n)
{
if(n==1||n==2){
return 1;}
else{
return(fiab(n-1)+fiab(n-2));}
return 0;
}
 

Write a C program to print the following Pattern

A) 1      
     1 2
     1 2 3
     1 2 3 4 


#include
#include
void main()
{
int i,j;
clrscr();
for(i=0;i<5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ", j);
}
printf("\n");
}
getch();
}


B)  1
      2 2
      3 3 3
      4 4 4 4 

#include
#include
void main()
{
int i,j;
clrscr();
for(i=0;i<5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ", i);
}
printf("\n");
}
getch();
}





Tuesday, February 22, 2011

Write a Visual Basic program to read the string first and find the reverse string and delete all the vowels

WAP in VB to read the string first and find the reverse string and delete all the vowels.
_____________________________________________________________

Dim a
Private Sub Command1_Click()
a = StrReverse(Text1.Text)
Label2.Caption = a
End Sub

Private Sub Command2_Click()
a = Replace(a, "a", "")
a = Replace(a, "A", "")
a = Replace(a, "e", "")
a = Replace(a, "E", "")
a = Replace(a, "i", "")
a = Replace(a, "I", "")
a = Replace(a, "o", "")
a = Replace(a, "O", "")
a = Replace(a, "u", "")
a = Replace(a, "U", "")
Label3.Caption = a
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 to find Sum, Average, Division, using command buttons

WAP to find Sum, Average, Division, using command buttons.
____________________________________________

Dim a, b, c, d, e
Private Sub Command1_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)
c = a + b
Label3.Caption = c
End Sub

Private Sub Command2_Click()
d = c / 2
Label3.Caption = d
End Sub

Private Sub Command3_Click()
e = a / b
Label3.Caption = e
End Sub

Private Sub Command4_Click()
End
End Sub

Private Sub Form_Load()

End Sub

___________________________________
OUTPUT
___________________________________



____________________________________
DOWNLOAD
____________________________________

Download its form

Download its Image



Write a Visual Basic program to find length of entered text

WAP to find length of entered text.
________________________________

Private Sub Command1_Click()
Dim a, b
a = Text1.Text
b = Len(a)
Label2.Caption = b
End Sub

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

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 to show your personal profile on the form

WAP to show your personal profile on the form.
_______________________________________

Dim a, b, c, d, e, f, g
Private Sub Command1_Click()
a = InputBox("Enter Your Name:")
b = InputBox("Enter Your Fathers Name:")
c = InputBox("Enter Your Department Name:")
d = InputBox("Enter Your Roll No. :")
e = InputBox("Enter Your Session:")
f = InputBox("Enter Your Address:")
g = InputBox("Enter Your Phone No. :")
End Sub

Private Sub Command2_Click()
Text1.Text = a
Text2.Text = b
Text3.Text = c
Text4.Text = d
Text5.Text = e
Text6.Text = f
Text7.Text = g
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 to Find the simple interest

WAP to Find the simple interest.
_______________________________
Private Sub Command1_Click()
Dim a
Dim b, c, d As Double

a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
d = (a * b * c) / 100
Label6.Caption = d




End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Label6.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 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 to check whether the given number is even or odd

WAP to check whether the given number is even or odd.
_____________________________________________

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 making a combo box which contains the country names and shows the capital for corresoponding country in another comb

WAP for making a combo box which contains the country names and shows the capital for corresoponding country in another combo box.
_______________________________________________________________



Private Sub Command1_Click()
If Combo1.ListIndex = 0 Then
Combo2.Clear
Combo2.AddItem ("NEW DELHI")
ElseIf Combo1.ListIndex = 1 Then
Combo2.Clear
Combo2.AddItem ("ISLAMABAD")
ElseIf Combo1.ListIndex = 2 Then
Combo2.Clear
Combo2.AddItem ("COLOMOW")
ElseIf Combo1.ListIndex = 3 Then
Combo2.Clear
Combo2.AddItem ("KATHMANDU")
ElseIf Combo1.ListIndex = 4 Then
Combo2.Clear
Combo2.AddItem ("TOKYO")
Else
MsgBox ("Select Valid Country")
End If
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
Combo1.AddItem ("INDIA")
Combo1.AddItem ("PAKISTAN")
Combo1.AddItem ("SRILANKA")
Combo1.AddItem ("NEPAL")
Combo1.AddItem ("JAPAN")
End Sub

_________________________________________________
OUTPUT
_________________________________________________


____________________________________
DOWNLOAD
____________________________________

Download its form

Download its Image



Write a Visual Basic programs for generating Fibonacci series.

WAP for generating Fibonacci series.
___________________________________

Private Sub Command1_Click()
List1.Clear
num = Val(Text1.Text)
a = 0
b = 1
c = 0
List1.AddItem (a)
List1.AddItem (b)
For i = 1 To num Step 1
c = a + b
List1.AddItem (c)
a = b
b = c
Next i
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
List1.Clear

End Sub
________________________________
OUTPUT
________________________________



DOWNLOAD

____________________________________

Download its form

Download its Image



Write a Visual Basic program to print the factorial of any number

WAP to print the factorial of any number.
___________________________________

Private Sub Command1_Click()
a = Val(Text1.Text)
Call fact(a)
End Sub

Private Sub Command2_Click()
End
End Sub
Public Function fact(a)
If a = 0 Then
fact = 1
Text2.Text = fact
Else
fact = a * fact(a - 1)
Text2.Text = fact
End If
End Function

Private Sub Form_Load()

End Sub

_____________________________________
OUTPUT
_____________________________________


____________________________________
DOWNLOAD
____________________________________

Download its form

Download its Image



Write a Visual Basic Program in which by moving the horizontal scroll bar the color of the font ranges and each of three horizontal scroll bar represe

WAP in which by moving the horizontal scroll bar the color of the font ranges and each of three horizontal scroll bar represents red, blue, green colors by using RGB built in function.
____________________________________________________________________
Private Sub Command1_Click()
'Text1.BackColor = 255
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Form_Load()
Text1.Enabled = False
HScroll1.Max = 255
HScroll1.Min = 0
HScroll1.SmallChange = 1
HScroll1.LargeChange = 2
HScroll1.Value = 255
HScroll2.Max = 255
HScroll2.Min = 0
HScroll2.SmallChange = 1
HScroll2.LargeChange = 2
HScroll2.Value = 0
HScroll3.Max = 255
HScroll3.Min = 0
HScroll3.Value = 0
HScroll3.SmallChange = 1
HScroll3.LargeChange = 2
End Sub

Private Sub HScroll1_Change()
Text1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub

Private Sub HScroll2_Change()
Text1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub

Private Sub HScroll3_Change()
Text1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub

__________________________________________________________
OUTPUT
__________________________________________________________



____________________________________
DOWNLOAD
____________________________________

Download its form

Download its Image