0% found this document useful (0 votes)
2 views8 pages

C Programs

The document contains multiple C programs that demonstrate basic mathematical operations and number properties. It includes implementations for calculating the power of a number, generating Fibonacci series, checking for prime numbers, identifying palindrome and Armstrong numbers, summing digits, reversing a number, and determining perfect numbers. Each program prompts the user for input and displays the result based on the respective mathematical logic.

Uploaded by

Bhumika Kamble
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

C Programs

The document contains multiple C programs that demonstrate basic mathematical operations and number properties. It includes implementations for calculating the power of a number, generating Fibonacci series, checking for prime numbers, identifying palindrome and Armstrong numbers, summing digits, reversing a number, and determining perfect numbers. Each program prompts the user for input and displays the result based on the respective mathematical logic.

Uploaded by

Bhumika Kamble
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// Power of a Number

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

void main()
{
int a,b,p=1,i;
clrscr();
printf(“\n Enter base and power”);
scanf(“%d%d”,&a,&b);
for(i=1;i<=b;i++)
{
p=p*a;
}
printf(“\n Power of a number=%d”,p);
getch();
}
//Fibonacci Series

#include<stdio.h>
#include<conio.h>
void main()
{
int n1=0,n2=1,n3,i,number;
clrscr();
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2);//printing 0 and 1
for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
getch();
}
//Prime Number

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

void main(){
int n,i,m=0,flag=0;
clrscr();
printf("Enter the number to check prime:");
scanf("%d",&n);
m=n/2;
for(i=2;i<=m;i++)
{
if(n%i==0)
{
printf("Number is not prime");
flag=1;
break;
}
}
if(flag==0)
printf("Number is prime");
getch();
}
//Palindrome Number

#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0,temp;
clrscr();
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf("palindrome number ");
else
printf("not palindrome");
getch();
}
//Armstrong Number

#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0,temp;
clrscr();
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
getch();
}
//Sum of Digits

#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0,m;
clrscr();
printf("Enter a number:");
scanf("%d",&n);
while(n>0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
printf("Sum is=%d",sum);
getch();
}
//Reversed Number

#include<stdio.h>
#include<conio.h>
void main()
{
int n, reverse=0, rem;
clrscr();
printf("Enter a number: ");
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf("Reversed Number: %d",reverse);
getch();
}
//Perfect Number

#include<stdio.h>
#include<conio.h>
void main(){
int n,i=1,sum=0;
clrscr();
printf("Enter a number: ");
scanf("%d",&n);

while(i<n){
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("%d is a perfect number",i);
else
printf("%d is not a perfect number",i);

getch();
}

You might also like