Showing posts with label find. Show all posts
Showing posts with label find. Show all posts
Monday, February 16, 2015
C program to find sum of elements above and below the main digonal of a matrix

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,m,n,d1=0,d2=0,a[5][5];
clrscr();
printf("How many rows and columns:");
scanf("%d%d",&m,&n);
printf("Enter matrix elements:
");
for(i=0;i<m;++i)
for(j=0;j<n;++j)
{
scanf("%d",&a[i][j]);
if(j>i)
d1+=a[i][j];
else
if(i>j)
d2+=a[i][j];
}
printf("Sum of elements above the digonal=%d
",d1);
printf("Sum of elements below the digonal=%d",d2);
getch();
}
Friday, February 13, 2015
C program to find largest and smallest element from a 1D array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i,n,large,small;
clrscr();
printf("How many elements:");
scanf("%d",&n);
printf("Enter the Array:");
for(i=0;i<n;++i)
scanf("%d",&a[i]);
large=small=a[0];
for(i=1;i<n;++i)
{
if(a[i]>large)
large=a[i];
if(a[i]<small)
small=a[i];
}
printf("The largest element is %d",large);
printf("
The smallest element is %d",small);
getch();
}
Thursday, February 12, 2015
C program to find LCM and HCF of two numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,hcf,lcm,max,min,r;
clrscr();
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
if(a>b)
{
max=a;
min=b;
}
else
if(b>a)
{
max=b;
min=a;
}
if(a==b)
hcf=a;
else
{
do
{
r=max%min;
max=min;
min=r;
}while(r!=0);
hcf=max;
}
lcm=(a*b)/hcf;
printf("
LCM=%d
HCF=%d",lcm,hcf);
getch();
}
Wednesday, February 11, 2015
C program to find whether a given character is an alphabet digit or any special character using ASCII values
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr(); //to clear the screen
printf("Enter any character:");
scanf("%c",&ch);
if((ch>=A&&ch<=Z)||(ch>=a&&ch<=z))#include<conio.h>
void main()
{
char ch;
clrscr(); //to clear the screen
printf("Enter any character:");
scanf("%c",&ch);
printf("
You have entered an alphabet");
else
if(ch>=0&&ch<=9)
printf("
You have entered a digit");
else
printf("
You have entered a special character");
getch(); //to stop the screen
}
Subscribe to:
Posts (Atom)