Saturday, 11 February 2012

print no. in accending order in array??

#include<stdio.h>
#include<conio.h>
void main()
{
                                    int n[5],i,j,t;
                                    for(i=0;i<5;i++)
                                    {
                                           printf("enter no::");
                                           scanf("%d",&n[i]);
                                    }
                                        for(i=0;i<5;i++)
                                        {
                                             for(j=0;j<5;j++)
                                              {
                                                   if(n[i]<n[j])
                                                   {
                                                           t=n[i];
                                                           n[i]=n[j];
                                                           n[j]=t;
                                                    }
                                               }
                                           }
                                                   printf("%d\n",n[i]);
                                 getch();
}

o/p:-
enter no:9
enter no:8
enter no:7
enter no:5
enter no:10
 5
 7
 8
 9
 10
                                             
 

Thursday, 9 February 2012

print prime no between up to n????

#include<stdio.h>
#include<conio.h>
void main()
{
            // print prime no
            int i,j,s,e,c=0,n;
            clrscr();
             printf("enter starting no\n");
             scanf("%d",&s);
             printf("enter ending no\n");
             scanf("%d",&e);
             if (s<e)
               {
                       for(j=s;j<=e;j++)
                          {
                               c=0;
                                      for(i=1;i<=j;i++)
                                         {
                                                if(j%i==0)
                                                   {
                                                          c++;
                                                    }
                                          }
                                            if(c==2)
                                             {
                                                     printf("\n%d",j);
                                             }
                            }
                             getch();
    }

print pettern????

                                          * * * * * * * *
                                          *                   *
                                          *                   *
                                          *                   *
                                          * * * * * * * *
#include<stdio.h>
#include<conio.h>
void main()
 {
                      // print pattern
                        int i,j,n;
                        printf("enter no\n");
                        scanf("%d",&n);
                        for(i=1;i<=n;i++)
                          {
                                  for(j=1;j<=n;j++)
                                       { 
                                             if (i==1 || i==n || j==1 || j==n)
                                                {
                                                       printf("*");
                                                 }
                                                 else
                                                     {
                                                            printf("  ");
                                                      }
                                          }
                                                printf("\n");
                                   }
                                        getch();
}                                                                                    
                                       

print fibonacci series pattern in triangle???

                                            1
                                       1        1
                                    1      1       2
                                1      1      2       3
                           1        1     2       3      5

 #include<stdio.h>
 #include<conio.h>
 void main()
 {
            //  print pattern
            int p,q,i,j,k,n,f;
            printf("enter no\n");
            scanf("%d",&n);
            for(i=1;i<=n;i++)
                   p=1;
                   q=0;
                     {
                          for(j=i;j<=n;j++)
                           {
                                 printf(" ");
                            }
                                   for(k=1;k<=i;k++)
                                   {
                                           f=p+q;
                                           printf("%d",f);
                                           p=q;
                                           q=f;
                                           printf("  %2d  ",f);
                                    }
                                            printf("\n\n");
                     }
               getch();
}

Wednesday, 8 February 2012

print below give sum of the series.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
 { 
                    // x+x^2/2!+x^3/3!+...... 
                   int  x,n,i,p,f;
                   float s=0;
                   f=1;
                   printf("enter the no\n");
                   scanf("%d",&n);
                   printf("enter the no\n");
                   scanf("%d",&x);
                    for(i=1;i<=n;i++)
                    {
                         f=f*i;
                         p=pow(x,i);
                         s=s+(p/f);
                     }
                        printf("%f",s);
                    getch();
 }

o/p:-
enter the no
10
enter the no
 0
 o.oooooo