Seach
Showing posts with label c. Show all posts
Showing posts with label c. Show all posts
INTEGER CALCULATOR USING FUNCTION
#include
#include
void main()
{
int a,b;
char choice;
//clrscr();
void call(int,int,char);
clrscr();
printf("+:addition\n-:subtraction\n*multiplication\n/:division\n%:modulo division");
printf("\nchoice");
scanf("%c",&choice);
printf("enter the numbers to perform arithamatic operations");
scanf("%d%d",&a,&b);
//scanf("%c",&choice);
calling(a,b,choice);
getch();
}
void call(int a,int b,char ch)
{
int x=a,y=b;
char c=ch;
//printf("enter the choice:");
//scanf("%c",&c);
switch(c)
{
case '+':
printf("addition %d +%d =%d",x,y,x+y);
break;
case '-':
printf("subtraction %d - %d =%d",x,y,x-y);
break;
case '*':
printf("multiplication %d * %d =%d",x,y,x*y);
break;
case '/':
printf("division %d/%d=%f",x,y,(float)x/y);
break;
case '%':
printf("modulo division %d % %d =%d",x,y,x%y);
break;
default:
printf("invalid choice:");
break;
}
}
PRIME NUMBER UP TO A RANGE WE ENTER
#include
#include
void main()
{
int i,j,count=0;
int l;
clrscr();
printf("enter the limit to find prime no:");
scanf("%d",&l);
printf("prime number serice:\n");
for(i=1;i<=l;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
count++;
}
if(count==2)
printf("%5d",i);
count=0;
}
getch();
}
binary search with location of the searching element
#include
#include
void main()
{
int c,l,m,n,f,s,a[10];
clrscr();
printf("enter the limit:");
scanf("%d",&n);
printf("enter the elements to array");
for(c=0;cl)
printf("not found");
}
getch();
}
Subscribe to:
Posts (Atom)