//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
Wednesday, September 30, 2009
Write a program to print tables in rows in C
WAP to print tables in 3 rows using for loop
prog:#include"stdio.h"
#include"conio.h"
void main()
{
int i, j,k;
clrscr();
for(i=1, j=2, k=3; i>=10, j<=20, k<=30; i=i+1, j=j+2, k=k+3) /* U can now add l=4, m=5..*/
{
printf("\n\n%d\t%d\t%d ", i, j, k); //\t= tab
}
getch();
}
output:
1 2 3
2 4 6
3 6 9
4 8 12
5 10 15
6 12 18
7 14 21
8 16 24
9 18 27
10 20 30
Labels:
C Programming,
for loop,
Loop,
Looping,
Table
Write programs to print Numerical & Symbolic Patterns using C
WAP to print the following numerical patterns
1)
5 5 5 5 54 4 4 4
3 3 3
2 2
1
2)
!! !
! ! !
! ! ! !..upto n
3)
** *
* * *
* * * *.. upto n
4)
11 2
1 2 3
1 2 3 4..upto n
5)
12 2
3 3 3
4 4 4 4..upto n
6)
* * *
* * *
* * * *..upto n
7)
1 2 1
3 2 1
4 3 2 1..upto n
8)
1 2 2
3 3 3
4 4 4 4..upto n
Click here to see solutions
Labels:
C Programming,
College,
for loop,
Loop,
Looping,
Numerical Pattern,
Pattern
Write programs to print alphabatical patterns using C
1) WAP to print the following pattern
AA B
A B C
A B C D
prog:
#include"stdio.h"#include"conio.h"
void main()
{
char i, j;
clrscr();
for(i='A'; i<='D'; i++)
{
for(j='A'; j<=i; j++)
{
printf("%c ", j);
}
printf("\n ");
}
getch();
}
Labels:
Alphabatical Pattern,
C Programming,
College,
Pattern
Subscribe to:
Posts (Atom)