Showing posts with label ignou assignment. Show all posts
Showing posts with label ignou assignment. Show all posts

Saturday, 5 November 2011

Decimal to Hexadecimal

Q.  Write a program in C to convert a decimal number to its hexadecimal equivalent.

Ans.

/*c program for convert decimal value to hexadecimal value*/
#include<stdio.h>
#include<conio.h>
void decTohex(int num);
int main()
{
 int n;
 printf("Enter number : ");
 scanf("%d",&n);
 decTohex(n);
 getch();
 return 0;
}
void decTohex(int num)
{
 int i=0,j=0,rem[5];
 for( ; num>15; num=num/16)
 {
   rem[i]=num%16;
   i++;
   j++;
 }
 rem[i]=num;
 for(i=j; i>=0; --i)
 {
   if(rem[i]==10)
      printf("A");
   else if(rem[i]==11)
      printf("B");

   else if(rem[i]==12)
      printf("C");

   else if(rem[i]==13)
      printf("D");

   else if(rem[i]==14)
      printf("E");

   else if(rem[i]==15)
      printf("F");

   else
      printf("%d",rem[i]);
 }
}



/*****************OUTPUT****************


Enter number : 1785
6F9


**************************************/

Tuesday, 27 September 2011

search prime number

Q. Write a C program to find whether a number is prime or not.
Definition of prime number:A prime number is one,which is divisible only by one or itself. And its must greater than 1.
And if number is not prime, it is called composite number and vice versa.

Ans.

#include<stdio.h>
#include<stdio.h>
int main()
{
 int x,num;
 printf("Enter number : ");
 scanf("%d",&num);
 x=2;
 while(x<=num-1)
 {
   if(num%x==0)
   {
      printf("Number is not prime!!");
      break;
   }
   x++;
 }
 if(x==num)
    printf("Number is prime!!");
 getch();
 return 0;
}

    output of above program :

Enter number : 7
Number is prime!!


Related Programs:

  1. Generate first n Prime number C program
  2. Print Prime Number 1 to 100 C program
  3. Flowchart for search prime number

Friday, 23 September 2011

search Max & Min numbers

/*program for searching minimum and maximum number in ten numbers*/

#include<stdio.h>
#include<conio.h>
int main()
{
 int arr[10];
 int i,num,min,max;
 for(i=0; i<10; i++)
 {
   printf("Enter %d Number : ",i+1);
   scanf("%d",&arr[i]);
 }
 min=max=arr[0];
 for(i=0; i<10; i++)
 {
   if(arr[i] < min)
      min=arr[i];
   else if(arr[i] > max)
      max=arr[i];
 }
 printf("\nMaixmum number is %d",max);
 printf("\nMinimum number is %d",min);
 getch();
 return 0;
}

      Output of above program :

Enter 1 Number : 55
Enter 2 Number : 36
Enter 3 Number : 45
Enter 4 Number : 78
Enter 5 Number : 156
Enter 6 Number : 11
Enter 7 Number : 1256
Enter 8 Number : 2
Enter 9 Number : 596
Enter 10 Number : 367

Maximum number is : 1256                       
Minimum number is :                        

Monday, 12 September 2011

Area of triangle program

Q. Write a function to find the area of a triangle whose length of three sides is given.

Ans.
 /*Program to area of triangle using Heron's Formula*/
 #include<stdio.h>
 #include<conio.h>
 #include<math.h
 int main()
 {
  int x=10,y=8,z=7;
  float s=0.0;
  double area=0;
  s=(x+y+z)/2.0;
  area=(s*(s-x)*(s-y)*(s-z));
  printf("\nArea of triangle = %lf",area);
  getch();
  return 0;
 }

/**************OUTPUT***************


Area of triangle = 773.43750075


************************************/

Shows logical operator

Q.2 Write a program in c for showing working of different logical operator in C.
Your program should guide user with proper message/menu on the console.
Ans.

/*c program to shows for working of logical operator*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int age,ch;
 char ms; //marital status
 printf("\nPlease Press Your Choice");
 printf("\nPress 1 for Logical AND operator");
 printf("\nPress 2 for Logical OR operator");
 printf("\nPress 3 for Logical NOT operator :");
 scanf("%d",&ch);
 switch(ch)
 {
  case 1 :
    printf("\n\nYou press 1 for logical AND operator\n");
    printf("\nA person is insured if he is married and his age>=30\n");
    fflush(stdin);
    printf("\nPerson married or unmarried Enter y/n : ");
    ms=getchar();
    printf("\nEnter person age : ");
    scanf("%d",&age);
    if((ms=='y' || ms=='Y')&& age>=30)
       printf("\nPerson is insured!!");
    else
       printf("\nPerson is not insured!!");
    break;

  case 2 :
    printf("\nYou press 2 for logical OR operator\n");
    printf("\nA person is insured either he is married or his age>=30\n");
    fflush(stdin);
    printf("\nPerson married or unmarried Enter y/n : "); 
    ms=getchar(); 
    printf("\nEnter your age : "); 
    scanf("%d",&age);
    if((ms=='y' || ms=='Y')|| age>=30) 
       printf("\nPerson is insured!!"); 
    else
       printf("\nPerson is not insured!!");
    break;
  
  case 3 :
    printf("\nYou press 3 for logical NOT operator\n");
    printf("\nA person is insured if he is married\n");
    fflush(stdin);
    printf("\nPerson married or unmarried Enter y/n : ");
    ms=getchar();
    if(!(ms=='y' || ms=='Y'))
       printf("\nPerson is insured");
    else
       printf("\nPerson is not insured");
    break;
  
  default :
    printf("\nYou press wrong number!");
 }
 getch();
 return 0;
}



         Output of the above program

Please Press Your Choice
Press 1 for Logical AND operator
Press 2 for Logical OR operator
Press 3 for Logical NOT operator:  1

You press 1 for logical AND operator


A person is insured if he is married and his age>=30


Enter y/n (y=married and n=unmarried) :


Enter your age : 31 


Person is insured!!

Logical NOT operator

Monday, 29 August 2011

Find out Factioral value


Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
 int fact=1,num;
 clrscr();
 printf("\nEnter Number : ");
 scanf("%d",&num);
 while(num>=1)
 {
  fact=fact*num;
  num--;
 }
 printf("\nFactorial value of %d is %d",num,fact);
}

       Output of above program : 
Enter Number : 5
Factorial value of 5 is 120