C Program to find the Largest Number using Ternary Operator

C Program to find the Largest Number using Ternary Operator | Ternary Operators in C | Ternary Operator Example in C | C Program to Find Biggest number out of given 3 numbers 





#include
void main()
{
       int a,b,c,big;
       printf("\n Enter 3 numbers:\n");
       scanf("%d %d %d",&a,&b,&c);
       big=(a> b&&a> c?a:b> c?b:c);
       printf("\n The biggest number is: %d",big);
       getch();
}




Related Links :

C program to find the factorial of the inputted number

C program to find the factorial of the inputted number



#include
void main()
{
     int n,i,fact=1;

     printf("Please Enter any number\n");
     scanf("%d",&n);

     for(i=n;i>=1;i--)
     {
                      fact=fact*i;
     }
     printf("\n factorial = \t %d",fact);
     getch();
     }


Related Links :

C Program to sort all even and odd numbers from array | Array Program to sort the Given numbers in C

C Program to sort all even and odd numbers from array | Array Program to sort the Given numbers in C



#include
#include
void main()
{
     int ar[100],i,n;

     printf("Enter the size of the array \n");
     scanf("%d",&n);

     printf("Enter the elements of the array \n");
     for(i=0; i<n; i++)
     {
           scanf("%d",&ar[i]);
     }

     printf("Even numbers in the array are - ");
     for(i=0;i<n;i++)
     {
           if(ar[i]%2==0)
           {
                 printf("%d \t",ar[i]);
           }
     }

     printf("\n Odd numbers in the array are - ");
     for(i=0;i<n;i++)
     {
           if(ar[i]%2!=0)
           {
                 printf("%d \t",ar[i]);
           }
     }
     getch();
}



Related Links :

C program to print palindrome series upto given number | palindrome series printing in C

C program to print palindrome series upto given number | palindrome series printing in C | palindrome series numbers printing in C



#include
void main()
{
     int limit,i2,n2,n3=0,i;
     
     printf("Enter limit to print all palindrome no. upto that limit \n");
     scanf("%d",&limit);
     
     for(i=1;i< =limit;i++)
     {
           i2=i;
           do
           {
                 n2=i2%10;
                 i2=i2/10;
                 n3=n3*10+n2;
           }
           while(i2>0);
           
           if(n3==i)
           {
               printf("%d \t",n3);
           }
           n3=0;
     }
     getch();
}



Related Links :

C program to find the factorial of given number | Factorial of number in C

C program to find the factorial of given number | Factorial of number in C | Assignment to find factorial in C Programming




#include
void main()
{
     int n,i,fact=1;

     printf("Enter any number\n");
     scanf("%d",&n);

     for(i=n;i>=1;i--)
     {
                      fact=fact*i;
     }
     printf("\n factorial = \t %d",fact);
     getch();
     }



Related Links :

C Program to find leap Year | Program to find given year leap year or not

C Program to find leap Year | Program to find given year leap year or not | Find Leap Year in C language



#include
#include
void main()
{
 int yr;
 clrscr();
 printf("enter the year");
 scanf("%d",&yr);
 if((yr%400==0)&&(yr/4==0))
  printf("leap year");
 else
  printf("not leap year");
 getch();
}




Related Links :

C Program to find absolute value of given number | C Language program to find absolute value of given number in C

C Program to find absolute value of given number | C Language program to find absolute value of given number in C



#include
#include
void main()
{
  int a,b;
  clrscr();
  printf("enter the value of a");
  scanf("%d",&a);
  if(a<0)
  {
   b=a*-1;
   printf("\nabsolute value of %d is %d",a,b);
  }
  else
   {
     printf("\nabsolute value=%d",a);
   }
   getch();
}




Related Links :

C Program to calculate Total, average in C | C assignment to calculate total and average C Program to calculate Total, average in C | C assignment to calculate total and average

C Program to calculate Total, average in C | C assignment to calculate total and average





#include
#include

int main()
{
  int a[5],i,tot=0,avg;
  clrscr();
  for(i=1;i< 6;i++)
  {
  printf("enter the marks of subjects");
  scanf("%d",&a[i]);

      tot=tot+a[i];
  }
  printf("total=%d\n",tot);
  avg=tot/5;
  printf("average=%d",avg);
  getch();
  return 0;
}



Related Links :

C Program to reverse the given Number | Reverse the given number in C

C Program to reverse the given Number | Reverse the given number in C | C Language assignment to reverse given number




/* wap yo find the reverse of the no.*/
#include
#include
int main()
{
   int a,b=0;
   clrscr();
   printf("enter the no.");
   scanf("%d",&a);
   while(a>0)
   {
       b=a%10;
       printf("%d",b);
       a=a/10;
   }
   getch();
   return 0;
}



Related Links :

C Program to find given number is Prime Number or Not | Program to find Prime Number

C Program to find given number is Prime Number or Not | Program to find Prime Number | Prime Number Assignment in C language




/* wap to find no. is prime or not */
#include
#include

int main()
{
  int num,x=2,p;
  clrscr();
  printf("enter the no");
  scanf("%d",&num);
  while(x<num)
  {
     if(num%x==0)
     {
	p=1;
	break;
     }
     else
     {
       p=0;
     }
     x++;
  }
  if(p==0)
  {
     printf("no.is prime");
  }
  if(p==1)
  {
     printf("no. is not prime");
  }
  getch();
  return 0;
}



Related Links :

Queue implementation on linked lists in C language

Queue implementation on linked lists in C language



/*
This is a program showing the queue implimentation on linked list
program writtem by RP Singh
compiled and tested on C-free4.0 standard
*/
#include
#include
#include
struct node1
{
    int item;
    struct node1 *next;
};
typedef struct node1 node;        //defining datatype node

struct q1
{
    node *front;
    node *rear;
    int length;
};
typedef struct q1 queue;        //defining queue datatype

void enqueue(node *, queue *);
node *dequeue(queue *);
int queue_length(queue *);
void view_queue(queue *);
node *create_node(void);
void fill_node(node *);


int main()
{
    int i,j;
    node *current_node;
    queue que;                    //local queue
    que.front=NULL;
    que.rear=NULL;
    que.length=0;
    printf("This is a demo program to show working of queues");
    anchor:                    //anchor is a label
    printf("\n\nyou have following options\n");
    printf("1. enqueue an item\n2. dequeue an item\n3. view queue\n");
    printf("4. count items in queue\n5. exit program\n\n");
    scanf("%d",&j);
    switch(j)
    {
        case 1:
            printf("\nEnter a number to be enqueued =>\t");
            current_node=create_node();
            fill_node(current_node);
            enqueue(current_node, &que);
            goto anchor;
        case 2:
            current_node = dequeue(&que);
            if(current_node)
            printf("The item %d dequeued successfully\n",current_node->item);
            goto anchor;
        case 3:
            view_queue(&que);
            goto anchor;
        case 4:
            printf("total items in the queue are %d\n",que.length);
            goto anchor;
        case 5:
            printf("Thank you\n");
            exit(0);
            goto anchor;
        default:
            printf("Invalid choice...!!!\n try choosing again\n\n");
            goto anchor;
    }
  
    return 0;
}

void enqueue(node *p,queue *q)                    //definition of enqueue function
{
    if(q->rear==NULL&&q->front==NULL)
    {
        q->rear=p;
        q->front=p;
    }
    else
    {
        q->rear->next=p;
        q->rear=p;
    }
    q->length++;
    printf("item %d enqueued successfully.\n",p->item);
}

node *dequeue(queue *q)                    //definition of dequeue function
{
    node *temp=NULL;
    if(q->rear==NULL&&q->front==NULL)        //this is the case when queue is empty
    {
        printf("queue is empty hence can not be dequeued\n");
        return temp;
    }
    else if(q->rear==q->front&&q->front!=NULL)    //this is the case when queue has only one node
    {
        temp=q->front;
        q->front=NULL;
        q->rear=NULL;
    }
    else
    {
        temp=q->front;
        q->front=q->front->next;
    }
    q->length--;
    return temp;
}

void view_queue(queue *q)
{
    node *temp_front;
    temp_front=q->front;
    if(q->length==0)
    {
        printf("\nThe queue is empty...!!!\n");
        return;
    }
    printf("The queue is\n");
    while(temp_front!=NULL)
    {
        printf("%d -> ",temp_front->item);
        temp_front=temp_front->next;
    }
    printf("\n");
    return;
}

node *create_node()                    //function to create a blank node
{
    node *temp;
    temp=(node*)malloc(sizeof(node));
    temp->next=NULL;
    return temp;
}

void fill_node(node *p)                    //function to fill a blank node with values taken from user
{
    int i;
    scanf("%d",&i);                    //this is the value taken from user
    p->item=i;
}



Related Links :

C Program to get nth term of Fibonacci series using recursion | Fibonacci series in C Language

C Program to get nth term of Fibonacci series using recursion | Fibonacci series in C Language | C Assignments to print Fibonacci using recursion function




#include
#include
int fibo(int x);

int main()
{
    int n,Tn;
    printf("Enter which term do you want?\n");
    scanf("%d",&n);
    if(n> 0)
    Tn=fibo(n);
    else
    exit(printf("term index entered should be natural number\n"));
    printf("T(%d) of fibonacci series = %d\n",n,Tn);
    return 0;
}

int fibo(int x)
{
    int term;
    if(x==1)
      term=1;
    else if(x==2)
      term=1;
    else
      term= fibo(x-1) + fibo(x-2);
    return term;
}


Related Links :

C Program to Find k'th root of a number in C | C assignments to find kth root of given number

C Program to Find  k'th root of a number in C | C assignments to find kth root of given number





#include
#include
main()
{
    printf ("*********a program to find k'th root of x ....\n\n");
    char c;
    float i,j,k,m;
    do
    {
    printf ("To get k'th root of x ....\n");
    printf ("type the values .....\n\n");
    printf ("x= "); 
    scanf("%f",&i);
    printf ("k=  ");
    scanf("%f",&k);
    j=pow(i,(1/k));
    printf("\n %dth root of%f = %f\n\n\n",(int)k,i,j);
    printf("do you want to try more? y/n \t");
    fflush(stdin);
    c=getchar();
    }while(c=='y');
}

Related Links :

C Program to find nth term of the series using recursion function

C Program to find nth term of the series using recursion function | nth term using recursion | recursion Function Example in C



#include
int get_term(int x);

int main()
{
    int n,Tn;
    printf("Enter which term do you want?\n");
    scanf("%d",&n);
    Tn=get_term(n);
    printf("T(%d) = %d\n",n,Tn);
    return 0;
}

int get_term(int x)
{
    int term;
    if(x==1)
      term=2;
    else
      term= get_term(x-1) + 1;
    return term;
}




Related Links :

C Program to transpose a 2D array | Transpose of Matrix in C

C Program to transpose a 2D array | Transpose of Matrix in C | C Assignments to Transpose of matrix



#include

void main()
{
     int a[10][10], b[10][10], m, n, i, j;
     
     printf("\nEnter number of rows & columns of aray : ");
     scanf("%d %d", &m, &n);
     
     printf("\nEnter elements of 2-D array:\n");
     for(i=0; i<m; i++)
     {
              for(j=0; j<n; j++)
              {
                       scanf("%d", &a[i][j]);
              }
     }
     
     printf("\n\n2-D array before transposing:\n\n");
     for(i=0; i<m; i++)
     {
              for(j=0; j<n; j++)
              {
                       printf("\t%d", a[i][j]);
              }
              printf("\n\n");
     }
     
     /* Transposing array */
     for(i=0; i<m; i++)
     {
              for(j=0; j<n; j++)
              {
                       b[j][i] = a[i][j];
              }
     }
     
     printf("\n\n2-D array after transposing:\n\n");
     for(i=0; i<n; i++)
     {
              for(j=0; j<m; j++)
              {
                       printf("\t%d", b[i][j]);
              }
              printf("\n\n");
     }
     getch();
}



Related Links :

Bisection Method Example In C Language

Bisection Method Example In C Language | C Program to show Bisection method

 


#include
#include
#include
//bisection method to solve the equation x^4-x-10=0//
float f(float x)
{
return(pow(x,4)-pow(x,1)-10);
}
void main()
{
float x,x1,a,b,err=0.00005; //err is the max error allowed
int i=1,n;
clrscr();
printf("enter the values of a,b and maximum iterations\n");
scanf("%f%f%d",&a,&b,&n);
x=(a+b)/2;
printf("iteration no. %d x=%10.5f\n",i,x);
i++;
while(i<n)
{
if(f(a)*f(x)<0) //checking for the signs
b=x;   //new interval (a,x)//
else
a=x;   //new interval (x,b)//
x=(a+b)/2;
printf("iteration no. %d x=%10.5f\n",i,x);
if(fabs(x1-x)<err)
{
printf("\nafter %d iterations, the value of root is %f\n",i,x);
break;
}
x1=x;
i++;
}
if(i>=n)
{
printf("\nsolution does not exist as iterations are not sufficient");
}
getch();
}



Related Links :

program to delete an element from the array in C | C Language Program to delete element from array

program to delete an element from the array in C | C Language Program to delete element from array | Deleting value from Array in C



#include< stdio.h> 

void main()
{
     int a[20], n, loc, item,i;
     
     printf("\n Enter size of an array : ");
     scanf("%d", &n);

     printf("\n Enter elements of an array:\n");
     for(i=0; i< n; i++)
     {
              scanf("%d", &a[i]);
     }
     
     printf("\n Enter location of deletion: ");
     scanf("%d", &loc);
     
     item = a[loc-1];
     for(i=loc-1; i< n; i++)
     {
              a[i] = a[i+1];
     }
     n--;
     printf("\nITEM deleted: %d", item);
     
     printf("\n\nAfter deletion:\n");
     for(i=0; i< n; i++)
     {
              printf("\n%d", a[i]);
     }
     getch();
}


Related Links :

C Program to draw SWASTIKA on center on the screen with blink effect | Blink Effect in C Language

C Program to draw SWASTIKA on center on the screen with blink effect | Blink Effect in C Language | C Program to Blink Swastik Symbol | creating swastika symbol in C



Draw a SWASTIK on center on the screen with blink effect.


#include<stdio.h> 
#include<conio.h> 
void main()
{
int i=0;
clrscr();
textcolor(RED+BLINK);
for(i=8;i<25;i++)
{
gotoxy(20,i); cprintf("*");
gotoxy(40,i); cprintf("*");
if(i<23)
{ 
gotoxy(20+2,i);
cprintf("*");
gotoxy(40+2,i+2); 
cprintf("*");
}
}

for(i=23;i<=40;i++)
{
if(i<39)
{
gotoxy(40,i);
cprintf("*");
gotoxy(60,i+2); 
cprintf("*");

}

gotoxy(40+2,i); 
cprintf("*");
gotoxy(60+2,i); c
printf("*");
}
for(i=20;i<42;i++)
{
gotoxy(i,25);
cprintf("*");
gotoxy(i,40); 
cprintf("*");
if(i<40)
{
gotoxy(i+2,25-2);
cprintf("*");
gotoxy(i,40-2); cprintf("*");
}
}
for(i=40;i<62;i++) 
{
if(i<60)
{
gotoxy(i+2,10);
cprintf("*");
gotoxy(i,25);
cprintf("*");
}
gotoxy(i,10-2); 
cprintf("*");
gotoxy(i,25-2); 
cprintfr*");
} 
getch();
}




OUTPUT IN C

Related Links :

C Program to print a linked list in reverse | Linked List in reverse order in C language

C Program to print a linked list in reverse | Linked List in reverse order in C language | C assignment to print linklist in reverse Order | Link list using malloc Function | creating runtime memory allocation in C | use of malloc() function in linklist





#include
#include
typedef struct linked_list
{
    int item;
    struct linked_list *next;
}node;

node *create_list();
void print_list(node *);
void print_list_in_reverse(node *);

int main()
{
    node *head=NULL;

    printf("you can create a list by entering elements press -999 to end\n");
    head=create_list();
    printf("\n The list is\n");
    print_list(head);
    printf("\n The list in reverse order is");
    print_list_in_reverse(head);
    printf("\n");
    return 0;
}

node *create_list()
{
    int x;
    node *temp=NULL;
    scanf("%d",&x);
    if(x!=-999)
    {
        temp=(node*)malloc(sizeof(node));
        temp->item=x;
        temp->next=NULL;
        temp->next=create_list();
    }
    return temp;
}
void print_list(node *p)
{
    if(p)
    {
        printf("%d ",p->item);
        print_list(p->next);
    }
    else
    printf("\n");
}

void print_list_in_reverse(node *p)
{
    if(p)
    {
        print_list_in_reverse(p->next);
        printf("%d ",p->item);
    }
    else
    printf("\n");
}

Related Links :

C Program to create Fibonacci series using recursion | Fibonacci series using recursion in C

C Program to create Fibonacci series using recursion | Fibonacci series using recursion in C | Fibonacci series with recursion function in C language



#include
#include
int fibo(int x);

int main()
{
    int n,Tn;
    printf("Enter which term do you want?\n");
    scanf("%d",&n);
    if(n>0)
    Tn=fibo(n);
    else
    exit(printf("term index entered should be natural number\n"));
    printf("T(%d) of Fibonacci series = %d\n",n,Tn);
    return 0;
}

int fibo(int x) // UD Function 
{
    int term;
    if(x==1)
      term=1;
    else if(x==2)
      term=1;
    else
      term= fibo(x-1) + fibo(x-2);
    return term;
}



Related Links :

binary Conversion of given Digit in C

binary Conversion of given Digit in C | C Program for binary Conversion | Digit to binary conversion in C



#include
main()
{
    int i=0,j,k,l,m;
    char str1[50],str2[50];
    printf("Enter a decimal integer => ");
    scanf("%d",&k);
    m=k;                   //it storing k for further use
    while(k>0){            //the while loop for storing remainder
       if(k%2==0)          //of each division by 2 in a string
       str1[i]='0';        //variable str1
       else
       str1[i]='1';
       k/=2;
       i++;
    }
    str1[i]='\0';
    l=i;
    j=i-1;
    for(i=0;j>=0;i++,j--)
      str2[j]= str1[i];
    printf("The binary equivalent of %d is ==> ",m);
    for(j=0;j<l;j++)
    putchar(str2[j]);
    getchar();
}



Related Links :

C Program to Print the Double Pyramid Pattern | creating double Pyramid in C

C Program to Print the Double Pyramid Pattern | creating double Pyramid in C | C assignment to create double Pyramid of Alphabets in C



#include
#include

void main()
{
int i,j,k;
int blank=0;
int lines = 6;
char symbol='A';
int temp ;
int diff[7]= {0,1,3,5,7,9,11};
clrscr();
k=0;
//Step 0

    for(i=lines;i>=0;i--)
    {
       printf("\n");
       symbol = 'A';

       for(j=i;j>=0;j--)    //step 1
            printf("%c ",symbol++);

       blank = diff[k++];   //step 2

       for(j=0;j<blank;j++)
            printf(" ");    //step 3


       symbol = 'F' - (blank/2);

       if (blank== 0)
           temp = i-1;
       else
           temp = i;

       for(j=0;j<=temp;j++)  //step 4
           printf("%c ",symbol--);

    }
getch();
}



Related Links :

C program to Pascal's triangle

Pascal's triangle in C language | C Program to create Pascal's triangle | Pascal's triangle in C 




#include
main()
{
    int i,j,k[50],l[50][50],m;
    printf("Enter the number of rows.");
    scanf("%d",&m);
    for(i=1;i<=m;i++)
    {
        for(j=0;j<(m-i);j++)
        printf("   ");
        for(j=0;j<i;j++)
        {
            k[0]=1;
            if(j==i-1)
            k[j]=1;
            l[i][j]=k[j];
            k[j+1]=l[i-1][j]+l[i-1][j+1];
            printf("%5d ",k[j]);
        }
        printf("\n");
    }
}

Related Links :

Triangle pyramid of Numbers in C

Triangle pyramid of Numbers in C | C Program to Print Inverse Triangle of Numbers in C




#include
#include
int main()
{
 int num,r,c,sp;
 printf("Enter loop repeat number : ");
 scanf("%d",&num);
 for(r=1; r<=num; r++)
 {
   for(sp=r; sp>1; sp--)
      printf(" ");
   for(c=r; c<=num; c++)
      printf("%d",c);
   for(c=num-1; c>=r; c--)
      printf("%d",c);
   printf("\n");
 }
 getch():
 return 0;
}





Related Links :

swapping two values using malloc function in C | Swapping Numbers using malloc in C

Swapping two values using malloc function in C | Swapping Numbers using malloc in C



#include
#include
struct stud
{
 char nam[30];
 struct stud *next;
};
struct stud *p,*q;
int main()
{
 p=(struct stud *)malloc(sizeof(struct stud));
 q=(struct stud *)malloc(sizeof(struct stud));
 printf("Enter name p : ");
 gets(p->nam);
 //fflush(stdin);
 printf("Enter name q : ");
 gets(q->nam);
 p->next=q;
 q->next=p;
 printf("\nName of p : %s",p->next->nam);
 printf("\nName of q : %s",q->next->nam);
 getch();
 return 0;
}


Output :
Enter name p : Ram
Enter name q : Shyam

Name of p : Shyam
Name of q : Ram

Related Links :

Program to shows Size of different data types in C | Printing Size of Data types in C

Program to shows Size of different data types in C | Printing Size of Data types in C


#include
#include
int main()
{
 int i;
 char ch;
 float f;
 long l;
 double d; 
 long double ld;
 printf("\n\tSize of different data types as following");
 printf("\n");
 printf("\nSize of character ch is %d",sizeof(ch));
 printf("\nSize of integer is %d",sizeof(i)); 
 printf("\nSize of float is %d",sizeof(f));
 printf("\nSize of long is %d",sizeof(l));
 printf("\nSize of double is %d",sizeof(d));
 printf("\nSize of long double is %d",sizeof(ld));
 getch();
 return 0;
}



Related Links :

swap numbers using call by reference in C program

swap numbers using call by reference in C program



#include
#include
void swaping(int *x, int *y);
int main()
{
 int n1,n2;
 printf("Enter first number (n1) : ");
 scanf("%d",&n1);
 printf("Enter second number (n2) : "); 
 scanf("%d",&n2);
 printf("\nBefore swapping values:");
 printf("\n\tn1=%d \n\tn2=%d",n1,n2);
 swaping(&n1,&n2);
 printf("\nAfter swapping values:");
 printf("\n\tn1=%d \n\tn2=%d",n1,n2);
 getch();
 return 0;
}
void swaping(int *x, int *y)
{
  int z;
  z=*x;
  *x=*y;
  *y=z;
} 



Related Links :

GCD or HCF of two numbers in C | C Program to find GCD and HCF

GCD or HCF of two numbers in C | C Program to find GCD and HCF



#include
 #include
 int main()
 {
  int n1,n2,rem;
  printf("Enter first number : ");
  scanf("%d",&n1);
  printf("Enter second number : ");
  scanf("%d",&n2);
  if(n2>n1)
  {
    n1=n1+n2;
    n2=n1-n2;
    n1=n1-n2;
  }
  do
{
      rem=n1%n2;
      n1=n2;
      n2=rem;
    }
while(rem!=0);
  printf("\nGCD of two number is %d",n1);
  getch();
  return 0;
 }


Related Links :

Addition of two 3x3 matrix in C | Addition on matrix in C

Addition of two 3x3 matrix in C | Addition on matrix in C

 


#include
#include
int main()
{
 int mata[3][3],matb[3][3],matc[3][3];
 int r,c,k;
 for(r=0; r<3; r++)
 {
  for(c=0; c<3; c++)
  {
    printf("Enter first matrix : ");
    scanf("%d",&mata[r][c]);
  }
 }
 for(r=0; r<3; r++)
 {
  for(c=0; c<3; c++)
  {
    printf("Enter second matrix : ");
    scanf("%d",&matb[r][c]);
  } 
 }
 for(r=0; r<3; r++)
 {
  for(c=0; c<3; c++)
  {
    matc[r][c]=0;
    for(k=0; k<3;k++)
       matc[r][c]=mata[r][c] + matb[r][c];
  }
 }
 printf("New addition matrix : \n"); 
 for(r=0; r<3; r++)
 {
  for(c=0; c<3; c++)
     printf(" %d",matc[r][c]);
  printf("\n");
 }
 getch();
 return 0;
}

Related Links :

C program for counting the number of characters and words in a given string

C program for counting the number of characters and words in a given string 


Program to find number Chars in given String, without strlen function, counting chars in given line


#include
#include
int main()
{
 int count_words=0,i;
 int count_char=0;
 char str[20];
 printf("Enter string : ");
 gets(str);
 for(i=0; str[i]!=NULL; i++)
 {
   count_char++;
   if(str[i]==' ')
      count_words++;
 }
 printf("\nNumber of characters in string : %d",count_char);
 printf("\nNumber of words in string : % d",count_words+1);
 getch();
 return 0;
}

Related Links :

C program to find whether a number is prime or not.

C program to find whether a number is prime or not.


Prime Number in C, C Program to find Prime Number, Prime Number in C Language, c Assignment for Prime Number


#include
#include
int main()
{
 int x,num;
 printf("Enter number : ");
 scanf("%d",&num);
 x=2;
 while(x<=num-1)
 {
   if(num%x==0)
   {
      printf("Number is not prime!!");
      break;
   }
   x++;
 }
 if(x==num)
    printf("Number is prime!!");
 getch();
 return 0;
}

Related Links :


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!