CHECKING LEAP YEAR USING C PROGRAM.

How To CHECKING LEAP YEAR USING C PROGRAM.


#include<stdio.h>#include<conio.h>void main(){    int year;    clrscr();    printf("Enter any year: ");    scanf("%d",&year);    if(((year%4==0)&&(year%100!=0))||(year%400==0))         printf("%d is a leap year",year);    else         printf("%d is not a leap year",year);    getch();}

PRINT PRIME NUMBERS BETWEEN 1-300 USING BREAK AND CONTINUE IN C

How To PRINT PRIME NUMBERS BETWEEN 1-300 USING BREAK AND CONTINUE IN C Program.


#include <math.h>
#include <stdio.h>
main()
{
  int i, j;
  i = 1;
  while ( i < 300 )
  {
            j = 2;
            while ( j < sqrt(i) )
            {
                        if ( i % j == 0 )
                                    break;
                        else
                        {
                                    ++j;
                                    continue;
                        }
            }
   if ( j > sqrt(i) )
            printf("%d\t", i);
    ++i;
  }
  return 0;
}

Write a c program to find out L.C.M. of two numbers.

How To Write a c program to find out L.C.M. of two numbers.



#include<stdio.h>
int main(){
  int n1,n2,x,y;
  printf("\nEnter two numbers:");
  scanf("%d %d",&n1,&n2);
  x=n1,y=n2;
  while(n1!=n2){
      if(n1>n2)
           n1=n1-n2;
      else
      n2=n2-n1;
  }
  printf("L.C.M=%d",x*y/n1);
  return 0;
}

Find g.c.d of two number using c program.

How To Find g.c.d of two number using c program.


#include<stdio.h>
int main(){
int n1,n2;
printf("\nEnter two numbers:");
scanf("%d %d",&n1,&n2);
while(n1!=n2){
if(n1>=n2-1)
n1=n1-n2;
else
n2=n2-n1;
}
printf("\nGCD=%d",n1);
return 0;
}

Write a c program to find out H.C.F. of two numbers.

How To Write a c program to find out H.C.F. of two numbers in C Program.


#include<stdio.h>
int main(){
int x,y,m,i;
printf("Insert any two number: ");
scanf("%d%d",&x,&y);
m=x
for(i=m;i>=1;i--){
if(x%i==0&&y%i==0){
printf("\nHCF of two number is : %d",i) ;
break;
}
}
return 0;
}

Check the given number is armstrong number or not using c program.

How To Check the given number is armstrong number or not using c program.

#include<stdio.h>
int main(){
int num,r,sum=0,temp;
printf("\nEnter a number:-");
scanf("%d",&num);
temp=num;
while(num!=0){
r=num%10;
num=num/10;
sum=sum+(r*r*r);
}
if(sum==temp)
printf("\nThe number %d is an armstrong number",temp);
else
printf("\nThe number %d is not an armstrong number",temp);
return 0;
}

Check given number is prime number or not using c program.

How To Check given number is prime number or not using c program.


#include<stdio.h>
int main(){
    int num,i,count=0;
    printf("\nEnter a number:");
    scanf("%d",&num);
    for(i=2;i<=num/2;i++){
        if(num%i==0){
         count++;
            break;
        }
    }
   if(count==0)
        printf("%d is a prime number",num);
   else
      printf("%d is not a prime number",num);
   return 0;

}

Write a c program to check given string is palindrome number or not.

How to Write a c program to check given string is palindrome number or not.


#include<string.h>
#include<stdio.h>
int main(){
  char *str,*rev;
  int i,j;
  printf("\nEnter a string:");
  scanf("%s",str);
  for(i=strlen(str)-1,j=0;i>=0;i--,j++)
      rev[j]=str[i];
      rev[j]='\0';
  if(strcmp(rev,str))
      printf("\nThe string is not a palindrome");
  else
      printf("\nThe string is a palindrome");
  return 0;
}

TO FIND FACTORIAL OF A NUMBER USING C PROGRAM

How TO FIND FACTORIAL OF A NUMBER USING C PROGRAM.


#include<stdio.h>
int main(){
  int i=1,f=1,num;
  printf("\nEnter a number:");
  scanf("%d",&num);
  while(i<=num){
      f=f*i;
      i++;
  }
  printf("\nFactorial of %d is:%d",num,f);
  return 0;
}

COPY DATA FROM ONE FILE TO ANOTHER FILE USING C PROGRAM

How To COPY DATA FROM ONE FILE TO ANOTHER FILE USING C PROGRAM.


#include<stdio.h>
int main(){
  FILE *p,*q;
  char file1[20],file2[20];
  char ch;
  printf("\nEnter the source file name to be copied:");
  gets(file1);
  p=fopen(file1,"r");
  if(p==NULL){
      printf("cannot open %s",file1);
      exit(0);
  }
  printf("\nEnter the destination file name:");
  gets(file2);
  q=fopen(file2,"w");
  if(q==NULL){
      printf("cannot open %s",file2);
      exit(0);
  }
  while((ch=getc(p))!=EOF)
      putc(ch,q);
  printf("\nCOMPLETED");
  fclose(p);
  fclose(q);
 return 0;
}

DISPLAY SOURCE CODE AS OUTPUT IN C PROGRAM

How To DISPLAY SOURCE CODE AS OUTPUT IN C PROGRAM.

#include<stdio.h>
int main(){
    FILE *p;
    char ch;
    p=fopen("raja.c","r");
    while((ch=getc(p))!=-1)
         putchar(ch);
    fclose(p);
    return 0;
}