0% found this document useful (0 votes)
23 views

N Prime Number

The document contains C code for several algorithms: 1) Finding the Nth prime number using a loop to check numbers up to 1000 for primality. 2) Checking if a number is a palindrome by reversing it and comparing. 3) Generating the Fibonacci series up to a given number using a recursive definition. 4) Calculating the greatest common divisor and least common factor of two numbers. 5) Checking if a character is a vowel or consonant with a switch statement.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

N Prime Number

The document contains C code for several algorithms: 1) Finding the Nth prime number using a loop to check numbers up to 1000 for primality. 2) Checking if a number is a palindrome by reversing it and comparing. 3) Generating the Fibonacci series up to a given number using a recursive definition. 4) Calculating the greatest common divisor and least common factor of two numbers. 5) Checking if a character is a vowel or consonant with a switch statement.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

NTH PRIME NUMBER

#include <stdio.h>
int main()
{
int check,n=0,c=0;
printf("Enter Prime Number you want to Find: ");
scanf("%d",&n);
for(int i=2;i<=1000;i++)
{
check=0;
for(int j=2;j<=i/2;j++)
{
if(i%j==0)
{
check=1;
break;
}
}
if(check==0)
c++;
if(c==n)
{
printf(" %dth Prime Number is:%d ",n,i);
break;
}
}
return 0;
}
PALINDROME OR NOT

#include <stdio.h>
int main()
{
int n, reverse = 0, t;
printf("Enter a number to check if it is a palindrome or not\n");
scanf("%d", &n);
t = n;
while (t != 0)
{
reverse = reverse * 10;
reverse = reverse + t%10;
t = t/10;
}
if (n == reverse)
printf("%d is a palindrome number.\n", n);
else
printf("%d isn't a palindrome number.\n", n);
return 0;
}

FIBONACCI SERIES UPTO ‘N’

#include<stdio.h>
int main()
{
int n,i;
printf("\nEnter the number upto which you want fibonacci series : ");
scanf("%d",&n);
long long int a[n];
a[0]=0;
a[1]=1;
for(i=2;i<n;i++)
{
a[i] = a[i-1] + a[i-2];
}
printf("\nThe Fibonacci Series is : \n");
for(i=0;i<n;i++)
{
printf("%d: %lld\n",i,a[i]);
}
return 0;
}
LCM & GCD

#include <stdio.h>
int main()
{
int n1, n2, gcd, lcm, r, num, deno;
printf("Enter two numbers\n");
scanf("%d %d", &n1, &n2);
if (n1 > n2)
{
num = n1;
deno = n2;
}
else
{
num = n2;
deno = n1;
}
r = num % deno;
while (r!= 0)
{
num = deno;
deno = r;
r = num % deno;
}
gcd = deno;
lcm = n1 * n2 / gcd;
printf("GCD of %d and %d = %d\n", n1, n2, gcd);
printf("LCM of %d and %d = %d\n", n1, n2, lcm);
}
VOWEL OR CONSONANT

#include <stdio.h> #include <stdio.h>


int main() int main()
{ {
char ch; char ch;
printf("Enter a character\n"); printf("Enter any alphabet: ");
scanf("%c", &ch); scanf("%c", &ch);
if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch switch(ch)
== 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch {
== 'U') case 'a':
printf("%c is a vowel.\n", ch); printf("Vowel");
else break;
printf("%c isn't a vowel.\n", ch); case 'e':
return 0; printf("Vowel");
} break;
case 'i':
printf("Vowel");
break;
case 'o':
printf("Vowel");
break;
case 'u':
printf("Vowel");
break;
case 'A':
printf("Vowel");
break;
case 'E':
printf("Vowel");
break;
case 'I':
printf("Vowel");
break;
case 'O':
printf("Vowel");
break;
case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
}
return 0;
}
LEAP YEAR

#include<stdio.h>
int main()
{
int yr;
printf("Enter a year");
scanf("%d",&yr);
if((yr%4==0 && yr%100!=0)|| yr%400==0)
printf("Leap Year");
else
printf("Not a Leap Year");
}

PERFECT NUMBER

#include <stdio.h>
int main()
{
int num,i,sum=0;
printf("Enter an integer number: ");
scanf("%d",&num);
for(i=1; i<num;i++)
{
if(num%i==0)
sum+=i;
}
if(sum==num)
printf("%d is a perfect number.",num);
else
printf("%d is not a perfect number.",num);
return 0;
}
SUM OF DIGITS

#include <stdio.h>
int main()
{
int n, t, sum = 0,r;
printf("Enter an integer\n");
scanf("%d", &n);
t = n;
while (t != 0)
{
r = t % 10;
sum = sum + r;
t/=10;
}
printf("Sum of digits of %d = %d\n", n, sum);
return 0;
}

MULTIPLICATION TABLE

#include <stdio.h>
int main()
{
int n,i;
printf("Enter an number\n");
scanf("%d", &n);
for(i=1;i<=10;i++)
{
printf("\n%d * %d = %d",n,i,n*i);
}
return 0;
}

You might also like