Nov 21, 2012

A program to find maximum number from a matrix



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10][10],m,n,p,q,max=0;
clrscr();
printf("no. of raws==>");
scanf("%d",&m);
printf("no. of columns==>");
scanf("%d",&n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%5d",a[i][j]);
}
printf("\n");
}
printf("\n\n");
max=a[0][0];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(max<a[i][j])
{
max=a[i][j];
}
}
}
printf("max=%d",max);
getch();
}


/* output
no. of raws==>3
no. of columns==>3
a[0][0]=54
a[0][1]=65
a[0][2]=32
a[1][0]=52
a[1][1]=65
a[1][2]=68
a[2][0]=95
a[2][1]=42
a[2][2]=32
   54   65   32
   52   65   68
   95   42   32
max=95
*/


Nov 20, 2012

A program to convert string in lower case to upper case



#include<stdio.h>
#include<conio.h>
void main()
{
char a[30];
int i,l;
clrscr();
puts("enter your string in lower case=");
gets(a);
l=strlen(a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]>='a'&&a[i]<='z')
{
a[i]=a[i]-32;
}
}
puts(a);
getch();
}


/* output
enter your string in lower case=
i am learning                                                                   
I AM LEARNING
*/


A C program to find area of triangle.


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
int base, altitude;
float area;
printf(“Enter base, altitude”);
scanf(“%d %d”, &base, &altitude);
area=1/2*base*altitude;
printf(“area of triangle is %f”,area);
getch( );
}



Nov 19, 2012

A program in C to SWAP the contents of 3 variables without using the temporary variables.

A program in C to SWAP the contents of 3 variables without using  the temporary variables.



 /* Swapping 3 numbers without using extra variable */
 #include< stdio.h >
 #include< conio.h >
 void Swap(int *a,int *b,int *c)
 {
    *a = *a + *b + *c;
    *b = *a - (*b + *c);
    *c = *a - (*b + *c);
    *a = *a - (*b + *c);
 }
 int main()
 {
    int x=1,y=2,z=3;
    clrscr();
    printf("BEFORE SWAPPING : %d %d %d\n",x,y,z);
    Swap(&x,&y,&z);
    printf("AFTER SWAPPING : %d %d %d",x,y,z);
   return(0);
 }/*end*/