Skip to main content

Posts

Showing posts from October, 2017

Program to find prime numbers between 1 and 50

#include<stdio.h> #include<conio.h> void main() {    int i, n=1, count;    clrscr();    printf("\nPrime numbers between 1 and 50\n");    while(n<=50)    {       count=0;       for (i=2; i<=n/2; i++)       { if(n%i==0) {     count++;     break; }       }       if (count==0)       { printf("\n%d",n);       }       n++;    }    getch(); } OUTPUT Prime numbers between 1 and 50 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47

Program to check whether the given number is prime or not

#include<stdio.h> #include<conio.h> void main() {   int n, i, count=0;   clrscr();   printf("\nEnter a number: ");   scanf("%d",&n);   for(i=2;i<=n/2;i++)   {     if(n%i==0)     {       count++;       break;     }   }   if(count==0)   {      printf("%d is a prime number",n);   }   else   {      printf("%d is not a prime number",n);   }   getch(); } OUTPUT: Enter a number: 11 11 is a prime number Enter a number: 25 25 is not a prime number

To Generate Fibonacci series using C

#include<stdio.h> #include<conio.h> void main() {    int f1=0, f2=1, f3, num, count=0;    clrscr();    printf("\nEnter a Number: ");    scanf("%d", &num);    printf("\n%d",f1);    printf("\n%d",f2);    count=2;        while(count<num)      {          f3=f1+f2;          count++;          printf("\n%d",f3);          f1=f2;          f2=f3;       }    getch(); } OUTPUT: Enter a Number: 10 0 1 1 2 3 5 8 13 21 34

Program to find the given string is a Palindrome or not using C

/*Program to find the given string is a Palindrome or not */ #include<stdio.h> #include<conio.h> #include<string.h> void main() {    char a[15];    int i, len, count=0;    clrscr();    printf("\nEnter a string: ");    scanf("%s", a);    len=strlen(a);    for(i=0; i<len; i++)    {       if(a[i]==a[len-i-1])       count=count+1;    }    if(count==len)    {      printf("\nThe given string is a Palindrome");    }    else    {      printf("\nThe  given string is not a Palindrome");    }    getch(); } OUTPUT: Enter a string:  hannah The given string is a Palindrome Enter a string:  welcome The given string is not a Palindrome

Palindrome of a given number using C

#include<stdio.h> #include<conio.h> void main() {    long n, r, ri=0, oi;    clrscr();    printf("\nEnter a number: ");    scanf("%ld",&n);    oi = n;    while(oi!=0)    {       ri = ri * 10;       ri = ri + oi % 10;       oi = oi / 10;    }    if(n==ri)    {       printf("\nThe given number is a Palindrome");    }    else    {       printf("\nThe given number is not a palindrome");    }    getch(); } Output: Enter a number: 1221 The given number is a Palindrome Output: Enter a number: 953212359 The given number is a Palindrome