//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
Saturday, November 7, 2009
Biggest Number From An Array Code Capsule C Programming
Labels:
Array,
Biggest Number,
C Programming,
Single Dimension Array
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
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
Labels:
C Programming,
Custom Header File,
Menu
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
#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
Labels:
Armstrong,
C Programming
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
#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
Labels:
C Programming,
Palindrome
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
#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
Labels:
C Programming,
reverse of number
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
#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
Labels:
C Programming,
Fibonacci Series
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 :
#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 :
Labels:
C Programming,
Factorial
Add Digits Of Any Fugure Number | C Programming
//wap to add digits of any figure no
#include
#include
void main()
{
int i,n,r,sum=0,d=1; //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);
for(i=1;i<=d;i++)
{
r=n%10;
sum=sum+r;
n=n%10;
if(n!=0)
{d++;}
}
printf(“\n\n\a\tthe sum is :%d”,sum);
getch();
}
or
#include
#include
void main()
{int n,sum=0,a,b,s;
clrscr();
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
while(n!=0)
{
s=n%10;
n=n/10;
sum=sum+s;
}
printf(“\n\n\a\tthe sum is :%d”,sum);
getch();
}
o/p→
enter a number : 12345
the sum is : 15
#include
#include
void main()
{
int i,n,r,sum=0,d=1; //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);
for(i=1;i<=d;i++)
{
r=n%10;
sum=sum+r;
n=n%10;
if(n!=0)
{d++;}
}
printf(“\n\n\a\tthe sum is :%d”,sum);
getch();
}
or
#include
#include
void main()
{int n,sum=0,a,b,s;
clrscr();
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
while(n!=0)
{
s=n%10;
n=n/10;
sum=sum+s;
}
printf(“\n\n\a\tthe sum is :%d”,sum);
getch();
}
o/p→
enter a number : 12345
the sum is : 15
Labels:
Add digits,
C Programming
Add digits of 3 digit no C programming
//wap to add digits of any 3 digit no
#include
#include
void main()
{int i,n,r,sum=0;
clrscr();
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
for(i=1;i<=3;i++)
{
r=n%10;
sum=sum+r;
n=n%10;
}
printf(“\n\n\a\tThe sum is :%d”,sum);
getch();
}
o/p→
enter a number : 123
The sum is : 6
#include
#include
void main()
{int i,n,r,sum=0;
clrscr();
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
for(i=1;i<=3;i++)
{
r=n%10;
sum=sum+r;
n=n%10;
}
printf(“\n\n\a\tThe sum is :%d”,sum);
getch();
}
o/p→
enter a number : 123
The sum is : 6
Labels:
Add digits,
C Programming
Check Prime Number C Programming
//wap to check if the no is prime or not
#include
#include
void main()
{int i,n,count=0;;
clrscr();
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{count++;}
} //counter
if(count>2)
{printf(“\n%d”,c);}
else
{printf(“\n prime”);}
getch();
}
o/p→
1 enter a number : 55
not prime
2 enter a number : 7
prime
#include
#include
void main()
{int i,n,count=0;;
clrscr();
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{count++;}
} //counter
if(count>2)
{printf(“\n%d”,c);}
else
{printf(“\n prime”);}
getch();
}
o/p→
1 enter a number : 55
not prime
2 enter a number : 7
prime
Labels:
C Programming,
Prime Number
Subscribe to:
Posts (Atom)