Tuesday, 22 September 2020

C Program to swap two number using Functions and Pointer's

September 22, 2020 Posted by Knowledge Bite No comments
#include<stdio.h>
#include<conio.h>
void main()
 {
   void swap(int*,int*);
   int a,b;
   clrscr();
   printf("Enter the value of a = ");
   scanf("%d",&a);
   printf("Enter the value of b = ");
   scanf("%d",&b);
   swap (&a,&b);
   printf("The value of a = %d \nThe value of b = %d",a,b);
   getch();
 }
 void swap(int *a,int *b)
  	{
    		int temp;
    		temp=*a;
    		*a=*b;
    		*b=temp;
  	}
    

C Program to find the number is a Prime Number or Not

September 22, 2020 Posted by Knowledge Bite No comments
#include<stdio.h>
#include<conio.h>
void main()
{
  int num,i;
  clrscr();
  printf("Enter the number = ");
  scanf("%d",&num);
  i=2;
  while (i<=num-1)
	{
		if (num%i==0)
			{
				printf("%d is not a prime number",num);
				break;
			}
		i++;
	}
		if (i==num)
			{
				printf("%d is a Prime Number",num);
			}
   getch();

}

C program to find the sum of digits of any 5 digit number

September 22, 2020 Posted by Knowledge Bite , No comments
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();   //to add the digits of any five digits number

int p,q,r,s,t,u,v,w,x,y;
printf("enter any number of five digit\n for which you want to add its digits\n");
scanf("%d",&p);
q=p%10;
r=p/10;
s=r%10;
t=r/10;
u=t%10;
v=t/10;
w=v%10;
x=v/10;
y=q+s+u+w+x;
printf("%d",y);
getch();
}
 
   

C Program to find the factorial of a number using Recursion

September 22, 2020 Posted by Knowledge Bite , , , 1 comment
#include <stdio.h>  
  
long factorial(int n)  
{  
  if (n == 0)  
    return 1;  
  else  
    return(n * factorial(n-1));  
}  
   
void main()  
{  
  int number;  
  long fact;  
  printf("Enter a Number: ");  
  scanf("%d", &number);   
   
  fact = factorial(number);  
  printf("Factorial of %d is %ld\n", number, fact);  
  getch();  
}