Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

Sunday, March 18, 2012

Program To print the two dimensional array.

//To print the two dimensional array.
#include<stdio.h>
#include<conio.h>
main()
{
      int a[3][3],i,j;
      printf("Enter the value of 3X3 array:-");
      for(i=0;i<3;i++)
      {
         for(j=0;j<3;j++)
          { scanf("%d",&a[i][j]);
          }
      } 
        printf("The 2D array is :");
        for(i=0;i<3;i++)
        { printf("\n\n");
         for(j=0;j<3;j++)
          { printf("%d  ",a[i][j]);
          }
        } 
        getch();
 }
          

To print the reverse of character.

//To print the reverse of character.
#include<stdio.h>
#include<conio.h>
main()
{     int i;
      char a[5];
      printf("Enter the name- ");
      for(i=0;i<5;i++)
      scanf("%c",&a[i]);
      printf("Your name is: ");
      for(i=0;i<5;i++)
      printf("%c",a[i]);
      printf("\nYour reverse  name is: ");
      for(i=4;i>=0;i--)
      printf("%c",a[i]);
      getch();
      }

Program To take character from the user by array .

//To take character from the user by array .
#include<stdio.h>
#include<conio.h>
main()
{     int i;
      char a[5];
      printf("Enter the name ");
      for(i=0;i<=4;i++)
      scanf("%c",&a[i]);
      printf("Your name is ");
      for(i=0;i<=4;i++)
      printf("%c",a[i]);
      getch();
      }

Saturday, March 17, 2012

Program for identify +ve and -ve no in an array .

Program for identify +ve and -ve no in an array .


#include<stdio.h>
#include<conio.h>
 main()
{
 int n[15],m,e,i;
 m=n[0];
 printf("Enter the 10 no ");
 for(i=0;i<10;i++)
 {
  scanf("%d",&n[i]);
 }

  printf("\nThe positive no are:\n");
  for(i=0;i<10;i++)
  {
   if(n[i]>0)
   {
    printf("%d,",n[i]);
   }
  }
  printf("\nThe negative no are:\n");
  for(i=0;i<10;i++)
  {
   if(n[i]<0)
   {
    printf("%d,",n[i]);
   }
  }
  getch();
}

Program to find odd and even nos. in an array.

//Program to find odd and even nos. in an array.
#include<stdio.h>
#include<conio.h>
 main()
{
 int n[10],i;
 printf("Enter the 10 no ");
 for(i=0;i<10;i++)
 {
  scanf("%d",&n[i]);
 }
   printf("The even nos: ");
  for(i=0;i<10;i++)
  {
   if(n[i]%2==0)
   {  
    printf("%d,",n[i]);
   }
         }
   printf("\nThe odd nos : ");
   for(i=0;i<10;i++)
   {
   if(n[i]%2!=0)
    { //o[i]=n[i];
   printf("%d,",n[i]);
    }
  
  }

                         
  getch();
}

Program for finding Largest no.

//Program for finding Largest no.
#include<stdio.h>
#include<conio.h>
 main()
{
 int n[15],m,i;
 printf("Enter the 10 no ");
 for(i=0;i<10;i++)
 {
  scanf("%d",&n[i]);
 }
 printf("The entered array is ");
  for(i=0;i<10;i++)
  {printf("   ");
  printf("%d",n[i]);
  }
  m=n[0];
  for(i=0;i<10;i++)
  {
   if(n[i]>m)
   {
    m=n[i];
   }
  }
  printf("\nLargest is %d",m);
    getch();
}

Program for addition of 10 no's.

//Addition of 10 no's.
#include<stdio.h>
#include<conio.h>
 main()
{
 int n[15],o=0,e,i;
    printf("Enter the 10 no ");
 for(i=0;i<5;i++)
 {
  scanf("%d",&n[i]);
 }
    printf("The entered array is ");
     for(i=0;i<5;i++)
  {printf("   ");
         printf("%d",n[i]);
  }
  for(i=0;i<5;i++)
  {
   o=o+n[i];
  }
  printf("Sum =%d",o);
  getch();
}