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 :





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




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



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


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

Write programs to print Numerical & Symbolic Patterns using C

 WAP to print the following numerical patterns

1)
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
2)
!
!  !
!  !  !
!  !  !  !..upto n
3)
*
*  *
*  *  *
*  *  *  *.. upto n
4)
1
1  2
1  2  3
1  2  3  4..upto n
5)
1
2  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



prog: 1)
#include"stdio.h"
#include"conio.h"
void main()
{
int i, j;
clrscr();
for(i=5; i>=1; i--)
{
for(j=1; j<=i; j++)
{
printf("%d ", i);
}
printf("\n ");
}
getch();
}

prog: 2)
#include
#include
void main()
{
int i, j, n;
printf("Enter the limit: ");
scanf("%d", &n);
  for (i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf(" ! ");           // now replace ! with any character
}printf("\n");
}
getch();
}

prog: 3)
#include
#include
void main()
{
int i, j, n;
printf("Enter the limit: ");
scanf("%d", &n);
  for (i=1; i<=n; i++)
 {
for(j=1; j<=i; j++)
{
printf(" * ");
}
printf("\n");
  }
getch();
}

prog: 4)
#include"stdio.h"
#include"conio.h"
void main()
{
int i, j;
clrscr();
for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf("%d ", j);
}
printf("\n ");
}
getch();
}

prog: 5)
#include"stdio.h"
#include"conio.h"
void main()
{
int i, j;
clrscr();
for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf("%d ", i);
}
printf("\n ");
}
getch();
}

prog: 6)
#include"stdio.h"
#include"conio.h"
void main()
{
int i, j, k, n;
clrscr();
printf("Enter the limit : ");
scanf("%d", &n);
for(i=1; i<=n; i++)
{
for(k=n-1; k>=i; k--)
{
printf(" ");
}
for(j=1; j<=i; j++)
{
printf("*");
 }
printf("\n ");
}
getch();
}


prog: 7)
#include"stdio.h"
#include"conio.h"
void main()
{
int i, j, k, n;
clrscr();
printf("Enter the limit : ");
scanf("%d", &n);
for(i=1; i<=n; i++)
{
for(k=n-1; k>=i; k--)
{
printf(" ");
}

for(j=i; j>=1; j--)
{
printf("%d", j);
 }
printf("\n ");
}
getch();
}

prog: 8)
#include"stdio.h"
#include"conio.h"
void main()
{
int i, j, k, n;
clrscr();
printf("Enter the limit : ");
scanf("%d", &n);
for(i=1; i<=n; i++)
{
for(k=n-1; k>=i; k--)
{
printf(" ");
}

for(j=i; j>=1; j--)
{
printf("%d", i);
 }
printf("\n ");
}
getch();
}



Write programs to print alphabatical patterns using C

1) WAP to print the following pattern
A
A 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();
}