Showing posts with label c programming. Show all posts
Showing posts with label c programming. Show all posts

Program to print table of the numbers from 1 to 10

//Program to print table of the numbers from 1 to 10
#include<stdio.h>
#include<conio.h>
int main()
{
  int row, col;
  clrscr();
  printf("Table of 1 to 10 is as\n");
  for(row=1;row<=10;row++)
  {
    for(col=1;col<=10;col++)
    {
      printf("%4d",row*col);
    }
    printf("\n");
  }
  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.



Program to print table of given number using for loop

//Program to print table of given number using for loop
#include<stdio.h>
#include<conio.h>
int main()
{
  int n,j,k;
  clrscr();
  printf("Enter a number\n");
  scanf("%d",&n);
  printf("Table of %d is as\n",n);
  for(j=1;j<=10;j++)
  {
    k=n*j;
    printf(" %d \n",k);
  }

  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to print table of given number

//Program to print table of given number
#include<stdio.h>
#include<conio.h>
int main()
{
 int n,k=1,m;
 clrscr();
 printf("Enter the number\n");
 scanf("%d",&n);
 while(k<11)
 {
   m=n*k;
   printf("%d*%d=%d\n",n,k,m);
   k++;
 }

  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to print sum of digits of the Integer

//Program to print sum of digits of the Integer
#include<stdio.h>
#include<conio.h>
int main()
{
  int n,rem,ans=0;
  clrscr();
  printf("Enter the number\n");
  scanf("%d",&n);
  while(n!=0)
  {
   rem=n%10;
   ans=ans+rem;
   n=n/10;
  }
  printf("The sum of digits is = %d",ans);
  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to print table between the given range of integers

//Program to print table between the given range
#include<stdio.h>
#include<conio.h>
int main()
{
  int row, col,y,k;
  clrscr();
  printf("Enter the two numbers for getting the table between their range\n");
  scanf("%d%d",&row,&col);
  k=row;
  printf("Table as\n");
  for(y=1;y<=10;y++)
  {
    for(row;row<=col;row++)
    {
      printf("%4d",row*y);
    }
    row=k;
    printf("\n");
  }
  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to accept a number and print its prime factors

//Program to accept a number and print its prime factors
#include<stdio.h>
#include<conio.h>
int main()
{
  int n,k=2,j;
  clrscr();
  printf("Enter the number\n");
  scanf("%d",&n);
  while(k<n)
  {
   if(n%k==0)
   {
     n=n/k;
     printf("%4d",k);
       if(n%k==0)
       printf("%4d",k);
   }
   k++;
  }
  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to display prime numbers between 1 to 100

//Program to display prime numbers between 1 to 100
#include<stdio.h>
#include<conio.h>
int main()
{
  int n,j;
  clrscr();
  printf("Prime numbers between 1 to 100\n");
  for(n=3;n<=100;n++)
  {
    for(j=2;j<=100;j++)
    {
     if(n%j==0)
     break;
    }
    if(j==n)
    printf("%4d",n);
  }
  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Progrm to print certain pattern

//Progrm to print following pattern
// * * * * *
// * * * * *
// * * * * *
// * * * * *
// * * * * *
#include<stdio.h>
#include<conio.h>
int main()
{
  int x,y;
  clrscr();
  for(x=1;x<=5;x++)
  {
     for(y=1;y<=5;y++)
     {
     printf(" * ");
     }

     printf("\n");
  }
  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to print unique pairs of numbers such that multiplication of the pair is given number

//Program to print unique pairs of numbers such that multiplication
//of the pair is given number
#include<stdio.h>
#include<conio.h>
int main()
{
 int n,k=1,j;
 clrscr();
 printf("Enter the number\n");
 scanf("%d",&n);
 while(k<n)
 {
 if(n%k==0)
 {
 if(k<n/k)
 printf("%d * %d = %d\n",k,n/k,n);
 }
   k++;
 }

  getch();
  return 0;
}

To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to find Gretest common divisor (GCD) using Euclidian algorithm.

//Program to find Gretest common divisor (GCD)
//using Euclidian algorithm.
#include<stdio.h>
#include<conio.h>
int main()
{
  int a,b,c,k,d;
  clrscr();
  printf("Enter two numbers\n");
  scanf("%d%d",&a,&b);
  c=a%b;
  printf("%d  * %d  =  %d\n",a,b,c);
  k=b<a?b:a;
  while(c>0)
   {
      if(d>0)
      {
        d=k%c;
        if(d!=0)
          printf("%d  *  %d  =  %d\n",k,c,d);
        k=c;
        c=d;
      }
   }
   printf("GCD of a and b is=%d",k);
   getch();
   return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to print all factors excluding number

//Program to print all factors excluding number
#include<stdio.h>
#include<conio.h>
int main()
{
  int n,k=1;
  clrscr();
  printf("enter the number\n");
  scanf("%d",&n);
  while(k<n)
  {
    if(n%k==0)
       printf("%4d",k);
    k++;
  }

  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to find out Factorial of given number

//Program to find out Factorial of given number
#include<stdio.h>
#include<conio.h>
int main()
{
  int n,j,k;
  clrscr();
  printf("Enter a number whose factorial you want to calculate\n");
  scanf("%d",&n);
  k=n;
  for(j=1;j<k;j++)
  {
     n=j*n;

  }
  printf("Factrorial of the %d is = %d",k,n);
  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to print a user entered character, to user entered number times

//Program to print a user entered character,
//to user entered number times
#include<stdio.h>
#include<conio.h>
int main()
{
  int n;
  char ch;
  clrscr();
  printf("Enter a number\n");
  scanf("%d",&n);
  printf("Enter character");
  fflush(stdin);
  scanf("%c",&ch);
  while(n>0)
  {
    printf("%c",ch);
    n--;
  }

  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to check the Armstrong Number

//Program to check the Armstrong Number
#include<stdio.h>
#include<conio.h>
int main()
{
  int num,sum=0,rem,onum;
  clrscr();
  printf("Enter the number\n");
  scanf("%d",&num);
  onum=num;
  while(num>0)
  {
    rem=num%10;

    num=num/10;
    sum=sum+rem*rem*rem;
  }
  if(sum==onum)
  printf("\nThe number is Armstrong number ");
  else printf("The number is not Armstrong number");
  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to display Armstrong numbers between 1 to 500

//Program to display Armstrong numbers between 1 to 500
#include<stdio.h>
#include<conio.h>
int main()
{
  int n,num,sum=0,rem,k;
  clrscr();
  printf("Armstrong numbers between 1 to 500 are\n");
  for(n=1;n<500;n++)
  {
     n=k;
     while(n>0)
     {
       rem=n%10;
       sum=sum+rem*rem*rem;
       n/10;
     }
     if(sum==k)
     printf("%d",k);
  }
   getch();
   return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to decide a quadrant of the entered point

//Program to decide a quadrant of the entered point
#include<stdio.h>
#include<conio.h>
int main()
{
float a,b;
clrscr();
printf("Enter the Co-ordinate of the point as x,y\n");
scanf("%f\n%f",&a,&b);
if(a>0&&b>0) printf("The Point lies in First Quadrant");
if(a>0&&b<0) printf("The Point lies in the Forth Quadrant");
if(a<0&&b<0) printf("The Point lies in the Third Quadrant");
if(a<0&&b>0) printf("The Point lies in the Second Quadrant");
if(a==0&&b!=0) printf("The Point lies on the X Axis");
if(a!=0&&b==0) printf("The Point lies on the Y Axis");
if(a==0&&b==0)printf("The Point is an Origin");
getch();
return 0;
}

To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to check whether user entered number is Positive of Negative or zero

//Program to check whether user entered number is Positive of Negative or zero
#include<stdio.h>
#include<conio.h>
int main()
{
int a;
clrscr();
printf("Enter any One Integer Numbers\n");
scanf("%d",&a);
if(a==0)
printf("Entered number is Zero");
else if(a>=1)
       printf("entered Integer is +ve");
       else if(a<0)
        printf("Entered Integer is -ve");

getch();
return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to check whether the user entered integer/number is Palindrome

//Program to check whether the user entered integer/number is Palindrome
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c,d,e;
long int f,g,h;
clrscr();
printf("Enter a Five Digit number ");
scanf("%d",&a);
h=a;
b=a/10000;a=a%10000;
c=a/1000;a=a%1000;
d=a/100;a=a%100;
e=a/10;a=a%10;
f=a;
f=f*10000;
e=e*1000;
d=d*100;
c=c*10;

g=b+c+d+e+f;
if(h==g)
printf("Number is palindrome",g);
else printf("Number is not palindrome");



getch();
return 0;

}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to display maximum of two integers using conditional operator

//Program to display maximum of two integers using conditional operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
printf("Enter Two Integer Numbers\n");
scanf("%d%d",&a,&b);
c=a>b?a:b;
printf("%d is Maximum",c);

getch();
return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

Program to display maximum of three integers using if else

//Program to display maximum of three integers using if else
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
printf("Enter Three Integer Numbers\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
    if(a>c) printf("%d is Maximum",a);
    else    printf("%d is Maximum",c);
}
else
{
    if(b>c) printf("%d is Maximum",b);
    else printf("%d is Maximum",c);
}


getch();
return 0;
}

To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.