Showing posts with label C Programing. Show all posts
Showing posts with label C Programing. Show all posts

Sunday, 28 December 2014

Program to Check if a number is Prime or not

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=2,count=0;
printf("Enter the No.\n");
scanf("%d",&n);
while(i<=n/2)
{
if(n%i==0)
count++;
i++;
}
if(count==0)
printf("The No. is Prime");
else
printf("The No. is Not Prime");
getch();
}

Program to Add,Subtract,Multiply,Divide

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,add,sub,mul,div;
printf("Enter the Value of a & b\n");
scanf("%d%d",&a,&b);
add=a+b;
sub=a-b;
mul=a*b;
div=a/b;
printf("Addition=%d\n Subtraction=%d\n Multiplication=%d\n Division=%d\n",add,sub,mul,div);
getch();
}



Program to convert Kilometer to Meter

#include<stdio.h>
#include<conio.h>
void main()
{
int km,mtr;
printf("Enter the Value\n");
scanf("%d",&km);
mtr=km*1000;
printf("Converted Value is &d",mtr);
getch();
}

Output

Enter the Value
5
Converted Value is 5000

Program to Swap two No.'s

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
printf("Enter The Values\n");
scanf("%d%d",&a,&b);
temp=a;
a=b;
b=temp;
printf("Swaping of No. is %d%d",a,b);
getech();
}

Output
Enter The Values
1
2
Swaping of No. is 2 1

Friday, 26 December 2014

Program to Input a no. and Sum it

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum;
printf("Enter The No. \n");
scanf("%d%d",&a,&b);
sum=a+b;
printf("Sum of two no. is%d",sum);
getch();
}

Output

Enter The No.
2
3
Sum of two no. is 5