#include
#include
void main()
{
int a,c1=0,c2;
clrscr();
printf("choose a no.");
scanf("%d",&a);
for(c2=1;c2<=a;c2++)
{
if (a%c2==0)
{
c1++;
}
if(c1!=2)
{
printf("%d is a prime no.",a);
}
else
{
printf("%d is not a prime no.",a);
}
}
getch();
}
#include
#include
void main()
{
int a[20],n,m,sum=0,sum2=0;
clrscr();
printf("enter the total no. to be inserted");
scanf("%d",&m);
clrscr();
for(n=1;n<=m;n++);
{
printf("enter ur value");
scanf("%d",&a[n]);
if (a[n]%2==0)
{
sum=sum+a[n];
}
else
{
sum2=sum2+a[n];
}
}
printf("sum of even no.s is %d",sum);
printf("\n sum of odd no.s is %d",sum2);
getch();
}
#include
#include
void main()
{
int c,p=1,x=1,max;
clrscr();
printf("enter max. value");
scanf("%d",&max);
printf ("%d%d",p,x);
while(max>x)
{
c=p+x;
x=p;
p=c;
printf("%d, ",c);
}
getch();
}
#include
#include
#include
void main()
{
int a,b,c,sum,div,sub,mul;
clrscr();
printf("enter ur choice");
printf("\n 1 Addition");
printf("\n 2 Subtraction");
printf(" \n 3 Multiplication");
printf("\n 4 Division");
printf("\n 5 Exit");
scanf("%d",&a);
printf("\n");
switch(a)
{
case 1:
printf("enter 2 no.s");
scanf("%d%d",&b,&c);
sum=b+c;
printf("ur result is %d",sum);
break;
case 2:
printf("enter 2 no.s");
scanf("%d%d",&b,&c);
sub=b-c;
printf("ur result is %d",sub);
break;
case 3:
printf("enter 2 no.s");
scanf("%d%d",&b,&c);
mul=b*c;
printf("ur result is %d",mul);
break;
case 4:
printf("enter 2 no.s");
scanf("%d%d",&b,&c);
div=a/b;
printf("ur result is %d",div);
break;
case 5:
exit(0);
break;
default:
printf("wrong choice");
}
getch();
}
decrement+increament-
#include
#include
void main()
{
int a,b,d,e;
clrscr();
for(a=1;a<=4;a++)
{
for(b=1;b<=a;b++)
{
printf("*");
}
printf("\n");
}
for(d=3;d>=1;d--)
{
for(e=d;e>=1;e--)
{
printf("*");
}
printf("\n");
}
getch();
}
______________
Output
--------------------
*
**
***
****
***
**
*
P1. (Greater of 3 no.s)
#include
#include
void main()
{
int a,b,c;
clrscr();
printf("enter 3 no.s of ur choice");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("%d is greater",a);
}
}
if(b>a)
{
if(b>c)
{
printf ("%d is greater",b);
}
}
if(c>a)
{
if(c>b)
{
printf("%d is greater",c);
}
}
getch();
}