Saturday, November 7, 2009

Biggest Number From An Array Code Capsule C Programming

//wap to find the biggest number from an array of 10 numbers.
#include<stdio.h>
#include<conio.h>
void main(){
int a[10], i;
clrscr();
printf(“\n \a enter 10 numbers in array : \n”);
for(i=0; i<=10; i++)
{scanf(“%d”,&a[i]);
}
for(i=0; i<=10; i++)
{if (big>a[i])
{big=a[i];}
}
printf(“\n\a biggest %d”, big);
getch();
}
o/p→
enter 10 numbers in array :
1 5 8 7 3 2 15 12 16 8
Biggest 19

Code Capsule 

Menu Program Using Custom Header Files | C Programming

//wap to create a menu where we have following options
1 for checking number is palindrome or not
2 for checkin’ the number is even or odd
3 for finding the factorials of number
4 to check the given no is armstorng or not
5 to exit the program

#include
#include
#include
#include”pal.c”
#include”arm.c”
#include”fact.c”
#include”evenodd.c”
void main()
{
int n,a;
charb=’y’;
clrscr();
do
{
printf(“\n\n Enter your choice\n****Menu****\n1 to check palindrom \n2 to check evenodd\n3to find tactorial\n4 to check armstrong\n5 to exit the program “);
scanf(“%d”,&a);

switch(a)
{
case 1: pal(a); break;
case 2: evenodd(a); break;
case 3: fact(a); break;
case 4: arm(a); break:
default: exit();
printf(“\n Do you want to continue(y/n)”);
scanf(“%c”,&b);
}while(b==’y’);
getch();
}
o/p→









Check Armstrong Number | C Programming

//wap to check if the no is Armstrong
#include
#include
void main()
{
int n=0,x,arm=0,r; //students are advised to use
clrscr(); // “long” instead of “int” so as to use high figure no
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
x=n;
while(x!=0){
r=x%10;
x=x/10;
arm=arm + pow(r,3);}
if(arm==n)
{printf(“\n Armstrong Number : %d”,arm);}
else
{printf(“\n Not Armstrong ”);}
}
o/p→
enter a number : 157
Armstrong : 157








To Check Palindrome | C Programming

//wap to check if the no is palindrome
#include
#include
#include
void main()
{
int i,n=, r=0, s=0, c=0, rev=0, x,y; //students are advised to use
clrscr(); // “long” instead of “int” so as to use high figure no
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
x=n; y=n;
while(n!=0){ // to count the digits
n=n/10;
c=c+1;}
printf(“\n The total digits in number : %d”,c);
while(x!=0){ //decrement of the power of 10
c=c-1;
r=x%10;
x=x/10;
rev=rev + r*pow(10,c);}

printf(“\n\n\a\tThe reverse is :%d”,rev);
if(rev==y)
{printf(“\n Palindrome”);}
else
{printf(“\n Not Plaindrome”)}
getch();
}
o/p→
enter a number : 12321
The reverse is : 12321
Plindrome


Reverse The Digits of Any Number | C Programming

//wap to reverse the digits of any number
#include
#include
#include
void main()
{
int i,n=, r=0, s=0, c=0, rev=0, x; //students are advised to use
clrscr(); // “long” instead of “int” so as to use high figure no
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
x=n;
while(n!=0){ // to count the digits
n=n/10;
c=c+1;}
printf(“\n The total digits in number : %d”,c);
while(x!=0){ //decrement of the power of 10
c=c-1;
r=x%10;
x=x/10;
rev=rev + r*pow(10,c);}

printf(“\n\n\a\tThe reverse is :%d”,rev);
getch();
}
o/p→
enter a number : 12345
The reverse is : 54321





Fibonacci Series | C Programming

//wap to print the fibbonacci series
#include
#include
void main()
{int i,a=0,b=1,c;
clrscr();
printf(“\n\n The fibonacci series : \n%d\n%d\n”,a,b);
for(i=1;i<=20;i++)
{
C=a+b;
Printf(“\n%d”,c);
A=b;
B=c;}
Getch();
}
o/p->
0 1 1 2 3 5 8 13 21 34 55



Find Factorial | C Programming

//wap to find factorial of any given no
#include
#include
void main()
{
int f=1, n, i;
clrscr();
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
for(i=n;i>1;i--) //or use for(i=1; i<=n; i++)
{
f=f*i;
}
printf(“\n\n\a\tThe Factorial is :%d”,f);
getch();
}

o/p→
enter a number :