Showing posts with label largest. Show all posts
Showing posts with label largest. Show all posts

Saturday, September 27, 2014

Largest Palindrome of 3 Numbers

If you have any doubts, let me know
#include <stdio.h>
#include <string.h>
#include<limits.h>

main()
{
    int i=999,j=999,sum=0,r=0,y,x,sum1=0,a[3000],k=0,temp;
    for(i=999;i>100;i--)
    {
        for(j=999;j>100;j--)
        {
            sum=i*j;
            x=sum;
            while(sum>0)
            {
             sum1=sum1*10;
             sum1=sum1+sum%10;
             sum=sum/10;
            }
            if(sum1==x)
         {
             a[k]=x;
             k++;
         }
            sum1=0;
        }
    }
   
    for(i=0;i<k;i++)
    for(j=0;j<k;j++)
    {
        if(a[i]<a[j])
        {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
printf("%d",a[k-1]);

}

Saturday, August 9, 2014

Largest and second largest of all rows and columns of a matrix.

This is a C program to find the largest and second largest element of all the rows and columns of a matrix. If you have any doubts, please feel free in asking.

#include<stdio.h>
main()
{
 int a[50][50],size,n,m,i,j,large,slarge;
 printf("enter size of matrix(row and column):");
 scanf("%d %d",&n,&m);
 printf("\n enter the elements:");
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
   scanf("%d",&a[i][j]);
 }
 printf("\n the inputed matrix is:\n");
 for(i=0;i<n;i++)
  {
   for(j=0;j<m;j++)
    printf("\t%d  ",a[i][j]);
   printf("\n");
  }
 for(i=0;i<n;i++)
  {
    slarge=a[i][0];
    large=a[i][0];
    for(j=0;j<m;j++)
     {
       if(large<a[i][j])
         large=a[i][j];
     }
    printf("\n the largest of row%d is %d",i+1,large);
    for(j=0;j<m;j++)
     {
       if(a[i][j]!=large)
       {
        if(slarge<a[i][j])
          slarge=a[i][j];
       }
     }
    printf("\nthe seceond largest of row%d is %d",i+1,slarge);
   }
 for(j=0;j<m;j++)
  {
    slarge=a[0][j];
    large=a[0][j];
   


for(i=0;i<n;i++)
    {
      if(large<a[i][j])
        large=a[i][j];
    }
    printf("\n the largest of column %dis %d",j+1,large);
    for(i=0;i<n;i++)
     {
       if(a[i][j]!=large)
        {
          if(slarge<a[i][j])
            slarge=a[i][j];
        }
     }
    printf("\nthe second largest of column %dis %d\n",j+1,slarge);
  }
 }

Program to print out largest of 3 numbers

Program to print out the largest of 3 numbers. If you have any doubts, please let me know.


#include<stdio.h> void main() { int large,x,y,z; printf("enter the 3 numbers"); scanf("%d",&x); scanf("%d",&y); scanf("%d",&z); large=(x>y?(x>z?x:z):(y>z?y:z)); printf("%d",large); }