Sei sulla pagina 1di 6

Even number program…..

#include<stdio.h>
#include<conio.h>
void main()
{
Int a;
Clrscr();
Printf(“Enter an Number..”);
Scanf(“%d”,&a);
If(a%2==0)
Printf(“It is even number”);
Else
Printf(“It is odd number”);
getch();
}

SUM OF SERIES
#include<stdio.h>
#include<conio.h>
void main()
{
Int n;
Sum=0;
Clrscr();
Printf(“enter the number”);
Scanf(“%d”,&n);
For(i=1;i<=n;i++)
{
Sum=sum+i;
}
Printf(“sum is…..”,sum);
Getch();
}

Output:
enter the number
5
Sum is 15
Explanation 1+2+3+4+5=15
SUM OF DIGITS
#include<stdio.h>
#include<conio.h>
void main()
{
Int n,r,sum;
Sum=0;
Clrscr();
Printf(“enter the number”);
Scanf(“%d”,&n);
While(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
Printf(“sum is…..”,sum);
Getch();
}

OUTPUT
enter the number
55
Sum is 10
Explanation 5+5=10

PALINDROME
#include<stdio.h>
#include<conio.h>
void main()
{
Int n,t;
t=n
S=0;
Clrscr();
Printf(“enter the number”);
Scanf(“%d”,&n);
While(n>0)
{
r=n%10;
s=(s*10)+r;
n=n/10;
}
If(t==s)
Printf(“it is palindrome number”);
else
Printf(“it is not a palindrome number);
Getch();
}

OUTPUT
enter the number
121
it is palindrome number

ARMSTRONG
#include<stdio.h>
#include<conio.h>
void main()
{
Int n,t;
t=n
S=0;
Clrscr();
Printf(“enter the number”);
Scanf(“%d”,&n);
While(n>0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
If(t==s)
Printf(“it is Armstrong number);
else
Printf(“it is not a Armstrong number);
Getch();
}

OUTPUT
enter the number
153
it is Armstrong number
FIBONACCI NUMBER

#include<stdio.h>
#include<conio.h>
void main()
{
Int n,a,b,c;
a=0;
b=1;
printf(“enter the number”);
scanf(“%d”,&n);
if(n==1)
printf(“the Fibonacci series is %d”,a);
else
printf(“the Fibonacci series is %d%d”,a,b);
if(n>2)
{
For(i=3;i<=n;i++)
{
C=a+b;
Printf(“%d”,c)
a=b;
b=c;
}
}
Getch();
}
OUTPUT:
enter the number
5
the Fibonacci series is
01123

PRIME NUMBER
#include<stdio.h>
#include<conio.h>
void main()
{
Int n,i,k;
Clrscr();
i=1;
K=0;
Printf(“enter the number”);
Scanf(“%d”,&n);
While(i<=n)
{
If(n%i==0)
K=k+1
i++
}
If(k==2)
Printf(“it is a prime number”);
Else
Printf(“It is not a prime number”);
Getch();
}

OUTPUT
enter the number
47
it is a prime number

Ascending and Desc prgm

#include<stdio.h>
#include<conio.h>
Void main()
{
Int a[20],i,j,t,n;
Clrscr();
Printf(“enter how many elements”);
Scanf(“%d”,&n);
For(i=0;i<n;i++)
Scanf(“%d”,&a[i]);
For(i=0;i<n-1;i++)
{
For(j=i+1;j<n;j++)
{
If(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
Printf(“Ascending Order of given nos”);
For(i=0;i<n;i++)
Printf(“%d”,a[i]);
Printf(“descending Order of given nos”);
For(i=n-1;i>=0;i--)
Printf(“%d”,a[i]);
Getch();
}

Potrebbero piacerti anche