Auto AdSense

Wednesday, 26 June 2013

C PROGRAM TO FIND THE REVERSE FORM OR IMAGE OF A GIVEN NUMBER USING WHILE LOOP.


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

main()
{
      int num,snum,digit,revfm;

      clrscr();

      printf("\n\n Enter a number to find its image : ");
      scanf("%d",&num);

      snum = num;
      revfm = 0;

      while(num > 0)
      {
                digit = num % 10;
                revfm = revfm * 10 + digit;
                num = num / 10;
      }
      printf("\n\n Image of the given number %d = %d\n\n",snum,revfm);

      return 0;
}

C PROGRAM TO PRINT ALL ELEMENTS OF FIBONACCI SEQUENCE between two limits


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

main()
{
      int pn,nn,cn,ll,ul;

      clrscr();

      printf("\n\n Enter Lower limit of fibonacci series : ");
      scanf("%d",&ll);
      printf("\n Enter Upper limit of fibonacci series : ");
      scanf("%d",&ul);

      pn = 0;
      nn = 1;
      cn = pn + nn;

      printf("\n\n FIBONACCI SERIES BETWEEN THE LIMITS %d and %d\n\n",ll,ul);

      while(cn <= ul)
      {
               cn = pn + nn;
               if(cn > ll && cn < ul)
                   printf(" %d",cn);
               pn = nn;
               nn = cn;
      }

      return 0;
}

C PROGRAM TO test the given number is an element of FIBONACCI sequence or not


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

main()
{
      int n,pn,nn,cn,num,flag;

      clrscr();

      printf("\n\n Enter a number to test : ");
      scanf("%d",&num);

      pn = 0;
      nn = 1;
      cn = pn + nn;

      printf("\n\n FIBONACCI SERIES\n\n");
      printf(" %d %d",pn,nn);

      flag = 1;

      while(cn <= num)
      {
               printf(" %d",cn);
               if(num == cn)
                   flag = 0;
               pn = nn;
               nn = cn;
               cn = pn + nn;
      }

      if( flag == 0)
          printf("\n\n The given number %d is a fibonacci element\n\n",num);
      else
          printf("\n\n The given number %d is not a fibonacci element\n\n",num);

      return 0;
}

C PROGRAM TO CHECK WHETHER THE NUMBER READ IS A PERFECT NUMBER OR NOT


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

main()
{
      int i,num,sum;

      clrscr();

      printf("\n\n Enter a number : ");
      scanf("%d",&num);

      i = 1;
      sum = 0;
      while(i < num)
      {
              if(num % i == 0)
                  sum = sum + i;
              i++;
      }

      if(sum != num)
          printf("\n The entered number %d is NOT A PERFECT NUMBER",num);
      else
          printf("\n The entered number %d is A PERFECT NUMBER",num);

      return 0;
}

C PROGRAM TO CHECK WHETHER THE NUMBER READ IS A PRIME NUMBER OR NOT


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

main()
{
      int i,num,flag;

      clrscr();

      printf("\n\n Enter a number : ");
      scanf("%d",&num);

      i = 2;
      flag = 0;

      while(i < num-1)
      {
              if(num % i == 0)
              {
                     flag = 1;
                     break;
              }
              i++;
      }

      if(flag == 1)
          printf("\n The enter number %d is NOT A PRIME NUMBER",num);
      else
          printf("\n The enter number %d is A PRIME NUMBER",num);

      return 0;
}

C PROGRAM TO CHECK THE GIVEN YEAR IS A LEAP YEAR OR NOT


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

main()
{
      int n;

      clrscr();

      printf("\n\n\tEnter a year : ");
      scanf("%d",&n);
      if((n%400==0)||((n%4==0)&&(n%100!=0)))
 printf("\n\n\tGiven year %d is a leap year",n);
      else
 printf("\n\n\tGiven year %d is not a leap year",n);

      return 0;
}

C Program to convert a positive integer below 2000 to a Roman numeral


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

int main()
{

    long int number;
    int j;

    clrscr();


    printf("\n\t\tPROGRAM TO DISPLAY INTEGER BELOW 2000 TO A ROMAN NUMERAL");

    printf("\n\n Enter a positive integer below 2000 : ");
    scanf("%ld",&number);

    printf("\n Roman number for the entered number %ld = ",number);
    if(number <= 0 || number > 2000)
    {
        printf("Invalid number");
        return 0;
    }

    while(number != 0)
    {
        if(number >= 1000)
        {
   for(j=0;j<number/1000;j++)
printf("%c",'M');
            number = number - (number/1000) * 1000;
        }
        else if(number >=500)
        {
            if(number < (500 + 4 * 100))
            {
for(j=0;j<number/500;j++)
   printf("%c",'D');
                number = number - (number/500) * 500;
            }
            else
            {
printf("%c%c",'C','M');
                number = number - (1000-100);
            }
        }
        else if(number >=100)
        {
            if(number < (100 + 3 * 100))
            {
for(j=0;j<number/100;j++)
   printf("%c",'C');
                number = number - (number/100) * 100;
            }
            else
            {

printf("%c%c",'C','D');
                number = number - (500-100);
            }
        }
        else if(number >=50)
        {
            if(number < (50 + 4 * 10))
            {
for(j=0;j<number/50;j++)
   printf("%c",'L');
                number = number - (number/50) * 50;
            }
            else
            {
printf("%c%c",'X','C');
                number = number - (100-10);
            }
        }
        else if(number >=10)
        {
            if(number < (10 + 3 * 10))
            {
for(j=0;j<number/10;j++)
   printf("%c",'X');
                number = number - (number/10) * 10;
            }
            else
            {
       printf("%c%c",'X','L');
                number = number - (50-10);
            }
        }
        else if(number >=5)
        {
            if(number < (5 + 4 * 1))
            {
for(j=0;j<number/5;j++)
   printf("%c",'V');
                number = number - (number/5) * 5;
            }
            else
            {
printf("%c%c",'I','X');
                number = number - (10-1);
            }
        }
        else if(number >=1)
        {
            if(number < 4)
            {
for(j=0;j<number/1;j++)
   printf("%c",'I');
                number = number - (number/1) * 1;
            }
            else
            {
printf("%c%c",'I','V');
                number = number - (5-1);
            }
        }
    }

    getch();
    return 0;
}

Thursday, 13 June 2013

C PROGRAM TO test the given number is an ARMSTRONG NUMBER or not


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

main()
{
      int num,snum,sum,digit;

      clrscr();

      printf("\n\n Enter a number to test : ");
      scanf("%d",&num);

      snum = num;
      sum = 0;

      while(num>0)
      {
                  digit = num % 10;
                  sum = sum + pow(digit,3);
                  num = num / 10;
      }

      if( snum == sum)
          printf("\n\n The given number %d is an ARMSTRONG NUMBER\n\n",snum);
      else
          printf("\n\n The given number %d is not an ARMSTRONG NUMBER\n\n",snum);

      return 0;
}

Monday, 10 June 2013

C++ program to calculate CGPA

//C++ program to calculate CGPA
using namespace std;
#include<iostream>
#include<conio.h>
int main()
{
int i,n,gp[20],c[20],sum,csum;
char g[20];
float cgpa;



cout<<"\n\t\t\t CGPA  Calculation";

cout<<"\n\n Enter number of Courses :";
cin>>n;

for(i=0;i<n;i++)
{
cout<<"\n\n Enter Grade of Course-"<<i+1;
cout<<" :";
cin>>g[i];
if(g[i]=='X'||g[i]=='x')
gp[i]=10;
else if(g[i]=='A'||g[i]=='a')
gp[i]=8;
else if(g[i]=='B'||g[i]=='b')
gp[i]=7;
else if(g[i]=='C'||g[i]=='c')
gp[i]=6;
else if(g[i]=='D'||g[i]=='d')
gp[i]=5;
else if(g[i]=='E'||g[i]=='e')
gp[i]=4;
else
gp[i]=0;

cout<<"\n Enter Credit of Course-"<<i+1;cout<<" :";
cin>>c[i];

}
sum=csum=0;

for(i=0;i<n;i++)
{
sum=sum+c[i]*gp[i];
csum=csum+c[i];
}
cgpa=(float)sum/csum;


cout<<"\n\n\n\n\n\n\t\tCongratulations\n\n\t\t\t\t Your CGPA is "<<cgpa;

getch();

return 0;
}

C program to calculate CGPA

/*
       In this program
             grades and their points are    X=10,A=8,B=7,C=6,D=5,E=4
                                                                                                            */


#include<stdio.h>
#include<conio.h>
void main()
{
int c[20],gp[20],i,sum=0,csum=0,n;
char g[20];
float cgpa;

clrscr();

printf("\n\t\t\t CGPA  Calculation");

printf("\n\n Enter number of Courses :");
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("\n\n Enter Grade of Course-%d :",i+1);
scanf("%c",&g[i]);

if(g[i]=='X'||g[i]=='x')
gp[i]=10;
else if(g[i]=='A'||g[i]=='a')
gp[i]=8;
else if(g[i]=='B'||g[i]=='b')
gp[i]=7;
else if(g[i]=='C'||g[i]=='c')
gp[i]=6;
else if(g[i]=='D'||g[i]=='d')
gp[i]=5;
else if(g[i]=='E'||g[i]=='e')
gp[i]=4;
else
gp[i]=0;
printf("\n\n Enter credits to Course-%d :",i+1);
scanf("%d",&c[i]);
}
for(i=0;i<n;i++)
{
sum=sum+c[i]*gp[i];
csum=csum+c[i];
}
cgpa=(float)sum/csum;

clrscr();

printf("\n\n\n\n\n\n\t\tCongratulations\n\n\t\t\t\t Your CGPA is  \"%f\" ",cgpa);

getch();
}


/*In this program you can calculate CGPA of  20 courses*/