Sunday, 23 December 2012

prime no


PRIME NO

#include<stdio.h>
int main()
{
int n,c;
printf("enter the no\n");
scanf("%d",&n);
if(n==2)
{
printf("prime\n");
}
else
{
for(c=2;c<=n-1;c++)
{
if(n%c==0)
{
break;
}
}
if(c!=n)
{
printf("not prime\n");
}
else
{
printf("prime\n");
}
}
}


Saturday, 15 December 2012

2D ARRAY


ARRAY DECLARE BY USER IN 2D

#include<stdio.h>
void main()
{
int a[3][3];
int b[3][3];
int i,j;
int suma=0,sumb=0;
float avga,avgb;
int maxa=0,maxb=0;
int mina=1000,minb=1000;
int sumc=0;
printf("printf the A array by user\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("printf the A array in 3*3\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("sum of the A array\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
suma=suma+a[i][j];
}
}
printf("%d\n",suma);
printf(" the avg of A array\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
avga=suma/9;
}
}
printf("%2f\n",avga);
printf("the max of A array\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(a[i][j]>=maxa)
{
maxa=a[i][j];
}
}
}
printf("%d\n",maxa);
printf("the min of A array\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(a[i][j]<=mina)
{
mina=a[i][j];
}
}
}
printf("%d\n",mina);
printf("print the B array by user\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&b[i][j]);
}
printf("\n");
}
printf("printf the B array in 3*3\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("sum of the B array\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
sumb=sumb+b[i][j];
}
}
printf("%d\n",sumb);
printf(" the avg of B array\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
avgb=sumb/9;
}
}
printf("%f\n",avgb);
printf("the max of B array\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(b[i][j]>=maxb)
{
maxb=b[i][j];
}
}
}
printf("%d\n",maxb);
printf("the min of B array\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(b[i][j]<=minb)
{
minb=b[i][j];
}
}
}
printf("%d\n",minb);
printf(" the sum of A and B array\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
sumc=suma+sumb;
}
}
printf("%d\n",sumc);

}

ASCII



ASCII

#include<stdio.h>
void main()
{
int a[255];
int i;
for(i=0;i<=254;i++)
{
a[i]=i;
}
for(i=0;i<=254;i++)
{
printf("%d=%c ",a[i]);
printf("%c  ",a[i]);
}
}

PRIME NO IN FACTOR


PRIME NO IN FACTOR


#include<stdio.h>

 void main()
 {
 int number,num;
 printf("Enter a number ");
 scanf("%d",&number);
 printf("\nThe prime factors of %d are:",number);
 for(num=2;num<=number;num++)
 {
 int i=2;
 while(i<=num-1)
 {
 if(num%i==0)
 {
 break;
 }
 i++;
 }
 if(i==num)
 {
 if(number%num==0)
 {
 number=number/num;
 printf("\t%d",num);
 num=1;
 }
 else
 {
 continue;
 }
 }
 }
 }

Wednesday, 12 December 2012

FACTORIAL NUMBERS

FACTORIAL PROGRAM WITHOUT FUNCTION

#include<stdio.h>
void main()
{
int fact=1,i,x;
printf("enter the no in factorial");
scanf("%d",&x);
for(i=1;i<=x;i++)
{

fact=fact*i;


}
printf("%d ",fact);

}

Monday, 10 December 2012

reverse the numbers

HOW TO REVERSE THE NUMBERS

#include<stdio.h>
int main()
{

int b=5432,c,d,e;
printf("enter the no in same way\n");
printf("%d \n",b);
c=b%10;
b=b/10;
printf("%d",c);
d=b%10;
b=b/10;
printf("%d",d);
e=b%10;
b=b/10;
printf("%d",e);
printf("%d",b);
printf("the reverse way \n");

}

Sunday, 9 December 2012

sum

How to add to no
#include<stdio.h>
int main( )
{
int a,b,sum;
a=2;
b=5;
sum=0;
sum=a+b;
printf("sum is");
getch( );
}