Armstrong,Reverse,Fiboncacci,Prime Number,ASCII Code Program

 USING LOOP


To display name


#include<stdio.h>
#include<conio.h>
void main()
{

int i;
i=1;
while(i<=10)
{
printf("programming is boring\n");
   i=i+1;
   }
    getch();
    }

Output:





























 1. Program to find reverse number

#include<stdio.h>
#include<conio.h>
void main()
{
int num,rem,rev=0;
printf("Enter the number");
scanf("%d",&num);
while(num>0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
printf("the reverse is %d",rev);
getch();
}
 Output:


2. Progran to check either number is palindrome or not

#include<stdio.h>
#include<conio.h>
void main()
{
int num,a,rem,rev=0;
printf("Enter the number");
scanf("%d",&num);
a=num;
while(num!=0)
{
rem=num%10;
rev=rev*10+rem;     ::::: palindrome:number which is same doing reverse also.eg:525
num=num/10;
}
if(a==rev)
{
printf("%d is palindrome",a);
}
else
{
printf("%d is not palindrome",a);
}
getch();
}

Output:

3. Program to find whether given no is armstrong or not

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int num,a,rem,sum=0;
printf("Enter the number");
scanf("%d",&num);
a=num;
while(num!=0)
{
rem=num%10;  :armstrong:cube number which sum  is equal to that no .eg:1^3+5^3+3^3=153
sum=sum+pow(rem,3);
num=num/10;
}
if(a==sum)
{
printf("%d is armstrong",a);
}
el
se
{
printf("%d is not armstrong",a);
}
getch();
}
Output:

























4. Program to determine a small,capital letter or a digit using ASCII code.


#include<stdio.h>
#include<conio.h>
void main()
{
char x;
printf("ENter the character");
scanf("%c",&x);
if(x>=65&&x<=90)
{
printf("%c is capital letter",x);
}
else if(x>=97&&x<=122)
{
printf("%c is small letter",x);
}
else if(x>=48&&x<=50)
{
printf("%c is digit",x);
}
else
{
printf("Enter the valid character");
}
getch();
}
Output:































5. Sum of number from 100 to 500 that are divisible by 5 & 7

#include<stdio.h>
#include<conio.h>
void main()
{
int sum=0;
int i;
for(i=100;i<=500;i++)
{
if(i%5==0&&i%7==0)
{
sum=sum+i;
}
}
printf(" %d is req sum",sum);
getch();
}
Output:                                                                                                             















6. To calculate factorial of a number

#include<stdio.h>
#include<conio.h>
void main()
{
int i,a,f=1;
printf("ENter the number");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
f=f*i;
}
printf("the factorial is %d",f);
getch();
}
Output:

                           

















7. Program for prime number from n1 to n2

#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,i,a,x,num;
printf("Enter the number\n");
scanf("%d %d",&n1,&n2);
for(num=n1;num<n2;num++)
{
x=0;
for(i=1;i<=num;i++)
{
a=num%i;
if(a==0)
{
x=x++;
}
}
if(x==2)
{
printf("%d\t",num);
}
}
getch();
}
Output:
   

8 Fibonacci series upto nth term

#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b=1,c,i,n;
printf("enter the number of terms\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
if(i<=1)
{
c=i;
}
else
{
c=a+b;
a=b;
b=c;
}
printf("%d\t",c);
}
getch();
}
Output:

                 11. Program for fibonacci series starting from 2
#include<stdio.h>
#include<conio.h>
void main()
{
   int a,b, c,n,sum,counter = 0;

   printf("Enter the term : ");
   scanf("%d", &n);

   printf("\nEnter First Number : ");
   scanf("%d", &a);

   printf("\nEnter Second Number : ");
   scanf("%d", &b);

   printf("\nFibonacci Series : %d  %d  ", a, b);

   while (counter < n)
   {
      sum = a+b;
      printf("%d  ", sum);
      a=b;
     b = sum;
      counter++;
   }

getch();
}
Output:
 

Comments