Thursday, 9 February 2012

print pascal triangle???

                                       1
                                     1   1 
                                   1   2   1
                                  1  3   3   1 
                                1  4   6   4   1 
                             1    5  10 10  5  1
 #include<stdio.h>
 #include<conio.h>
 void main()
 {
                    // print pascal triangle
                      int n,g;
                      int i,k,j;
                      clrscr();
                      printf("enter no\n");
                      scanf("%d",&n);
                      for(i=0;i<=n;i++)
                      {
                          for(j=i;j<=n;j++)
                          {  
                                   printf("  ");
                           }
                                g=1;
                                   for(k=0;k<=i;k++)
                                    {
                                         if(i==0 || k==0)
                                               printf("  %2d  ",g);
                                                else
                                                 {  
                                                          g=g*(i-k+1)/k;
                                                           printf("   %2d  ",g);
                                                   }
                                       }
                                              printf("\n\n");
                             }
                                      getch();
  }

Thursday, 12 January 2012

w.a.p to print no is even or odd.

#include<stdio.h>
#include<conio.h>
void main()
{
     // print no is even or odd
      int a;
       printf("enter number::\n");
       scanf("%d",&a);
       if (a%2==0)
      {
          printf("no. is even\n);
      }
       else
       {
           printf("no. is odd\n");
       }
        getch();
}
out put:-
enter number::
2
no is even

w.a.p to print number positive or negative.

#include<stdio.h>
#include<conio.h>
void main()
{
    // print no. is positive or negative
     int a;
     clrscr();
     printf("enter number::\n");
     scanf("%d",&a);
     if (a>0)
     {
         printf("no. is positive\n");
     }
      else
      {
         printf("no. is negative\n");
       }
       getch();
}
out put:-
enter number
-5
no. is negative