/* C Program To Find Armastrong Number of a Number */
#include< stdio.h>
#include< conio.h>
#include< math.h>
void main()
{
long int d1,d2,d3;
int i,temp;
clrscr();
printf("The armstrong numbers are:\n");
for(i=1;i<=500;i++)
{
d1=i%10;
temp=i;
temp=temp/10;
d2=temp%10;
d3=temp/10;
if((pow(d1,3)+pow(d2,3)+pow(d3,3))==i)
printf("%d\n",i);
}
getch();
}
Sunday, March 13, 2011
Friday, February 19, 2010
C Program To Find Largest Number In An Array Using Function
/* C Program To Find Largest Number In An Array Using Function */
#include< stdio.h>
void main()
{
int i,n,a[5],max,min;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the array element \n");
for(i=0;i {
scanf("%d",&a[i]) ;
}
mn(a,n,max,min);
getch();
}
int mn(int *a,int n,int max,int min)
{
int i;
min=max=a[0];
for(i=1;i<=n;i++)
{
if(a[i]>max)
{
max=a[i];
}
if(a[i] {
min=a[i];
}
}
printf("maximum=%d",max);
printf("minimum=%d",min);
return 0;
}
#include< stdio.h>
void main()
{
int i,n,a[5],max,min;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the array element \n");
for(i=0;i
scanf("%d",&a[i]) ;
}
mn(a,n,max,min);
getch();
}
int mn(int *a,int n,int max,int min)
{
int i;
min=max=a[0];
for(i=1;i<=n;i++)
{
if(a[i]>max)
{
max=a[i];
}
if(a[i]
min=a[i];
}
}
printf("maximum=%d",max);
printf("minimum=%d",min);
return 0;
}
Tuesday, February 16, 2010
C Program to Convert A String From Lower TO Upper Letters And Vice-Versa
/* C Program to Convert A String From Lower TO Upper Letters And Vice-Versa */
#include< stdio.h>
#include< ctype.h>
#include< conio.h>
void upper(char instr[])
{
int i=0;
while(instr[i])
{
instr[i]=toupper(instr[i]);
i++;
}
}
void lower(char instr[])
{
int i=0;
while(instr[i])
{
instr[i]=tolower(instr[i]);
i++;
}
}
void main()
{
char instr[100],inchar;
clrscr();
printf("input the string\n");
gets(instr);
printf("To upper-or-lower case(u/l)?\n");
scanf("%c",&inchar);
switch(inchar)
{
case 'u':
case 'U':
upper(instr);
break;
case 'l':
case 'L':
lower(instr);
break;
default:
printf("invalid");
}
printf("the converted string is...\n");
printf("%s\n",instr);
getch();
}
#include< stdio.h>
#include< ctype.h>
#include< conio.h>
void upper(char instr[])
{
int i=0;
while(instr[i])
{
instr[i]=toupper(instr[i]);
i++;
}
}
void lower(char instr[])
{
int i=0;
while(instr[i])
{
instr[i]=tolower(instr[i]);
i++;
}
}
void main()
{
char instr[100],inchar;
clrscr();
printf("input the string\n");
gets(instr);
printf("To upper-or-lower case(u/l)?\n");
scanf("%c",&inchar);
switch(inchar)
{
case 'u':
case 'U':
upper(instr);
break;
case 'l':
case 'L':
lower(instr);
break;
default:
printf("invalid");
}
printf("the converted string is...\n");
printf("%s\n",instr);
getch();
}
Wednesday, February 10, 2010
C Program To Find Sum Of Two Integer Numbers
/* C Program to find sum of two integer numbers */
# include< stdio.h>
# include< conio.h>
void main()
{
int a,b,sum;
clrscr();
printf("enter the number\n");
scanf("%d%d",&a,&b);
sum=a+b;
printf("SUM=%d",sum);
getch();
}
# include< stdio.h>
# include< conio.h>
void main()
{
int a,b,sum;
clrscr();
printf("enter the number\n");
scanf("%d%d",&a,&b);
sum=a+b;
printf("SUM=%d",sum);
getch();
}
C Program To Find Simple Interest
/* C Program to find Simple Interest */
#include< stdio.h>
#include< conio.h>
void main()
{
float p,t,r,si;
clrscr();
printf("Enter the value for principle_amt,time,rate\n");
scanf("%f%f%f",&p,&t,&r);
si=p*t*r/100;
printf("Simple Interest=%f",si);
getch();
}
#include< stdio.h>
#include< conio.h>
void main()
{
float p,t,r,si;
clrscr();
printf("Enter the value for principle_amt,time,rate\n");
scanf("%f%f%f",&p,&t,&r);
si=p*t*r/100;
printf("Simple Interest=%f",si);
getch();
}
Sunday, February 7, 2010
Sample C Program
/* Sample C Program */
#include< stdio.h> // Preprocessor Directive
main() // Main Starts from Here
{
clrscr(); //Clear screen
printf("WELCOME TO C"); // Print Statement
}
#include< stdio.h> // Preprocessor Directive
main() // Main Starts from Here
{
clrscr(); //Clear screen
printf("WELCOME TO C"); // Print Statement
}
Subscribe to:
Posts (Atom)