Important Program of C language in O level exam january 2019

Important Program of C language in O level exam january 2019

Lucas Numbers similar to the Fibonacci series that often occurs when working with the Fibonacci series. Edouard Lucas (1842-1891) (who gave the name "Fibonacci Numbers" to the series written about by Leonardo of Pisa) studied this second series of numbers: 2, 1, 3, 4, 7, 11, 18, .. called the Lucas numbers in his honour. On this page we examine some of the interesting properties of the Lucas numbers themselves as well as looking at its close relationship with the Fibonacci numbers. The following page generalises further by taking any two starting values.

#include<stdio.h>
void main()
{
    int a,b,c;
    clrscr();
    a=1;

    b=3;
    printf("\n\t%d\t%d",a,b);
    c=0;
    while(c<50)
    {
    c=a+b;
     a=b;
     b=c;

     printf("\t%d",c);

    }

Write a program to convert a number into its equivalent word without using character array?

#include <stdio.h>
#include <math.h>
int main()
{
    int n, num = 0, digits;
    printf("Enter any number to print in words: ");
    scanf("%d", &n);
   
    /* Find total digits in n */
    digits = (int) log10(n);

    /* Store reverse of n in num */
    while(n != 0)
    {
        num = (num * 10) + (n % 10);
        n /= 10;
    }
   
    /* Find total trailing zeros */
    digits =  digits - ((int) log10(num)); 

    /*
     * Extract last digit of number and print corresponding number in words
     * till num becomes 0
     */
    while(num != 0)
    {
        switch(num % 10)
        {
            case 0:
                printf("Zero ");
                break;
            case 1:
                printf("One ");
                break;
            case 2:
                printf("Two ");
                break;
            case 3:
                printf("Three ");
                break;
            case 4:
                printf("Four ");
                break;
            case 5:
                printf("Five ");
                break;
            case 6:
                printf("Six ");
                break;
            case 7:
                printf("Seven ");
                break;
            case 8:
                printf("Eight ");
                break;
            case 9:
                printf("Nine ");
                break;
        }
       
        num /= 10;
    }
   
    /* Print all trailing zeros */
    while(digits)
    {
        printf("Zero ");
        digits--;
    }
   
    return 0;
}

Write a program using pointer to find greatest number in an array.


#include<stdio.h>
#define MAX 5
void main()
{
     int ar[MAX],*pt,h,i;
     for(i=0;i<MAX;i++)
     {
          printf("Enter Number>> ");
          scanf("%d",&ar[i]);
     }

     h=ar[0];
     for(pt=ar,i=0;i<MAX;pt++,i++)
     {
          if(*pt>h)
              h=*pt;
     }
     printf("Highest Value is %d",h);

}

Define void data type and write any three use of it.


The data type void actually refers to an object that does not have a value of any type. Void is also used to indicate when a function does not return a value or no argument. Such a function is used for its side effect and not for its value. In the function declaration and definition, we have indicated that the function does not return a value by using the data type void to show an empty type, i.e. no value. Similarly, when a function has no formal parameters, the keyword void is used in the function prototype and header to signify that there is no information passed to the function.



1. When used as a function return type:
the void keyword specifies that the function does not return a value. 

void show()
 {
      printf("This function has no return type");
 }



2. When used for a function's parameter list:
void specifies that the function takes no parameters.

int sum(void)
 {
      int a,b;
      printf("Enter Two number>> ");
      scanf("%d%d",&a,&b);
      return a+b;
 }

3. When used in the declaration of a pointer:
void specifies that the pointer is "universal."

void main()
{
     void *p;
     int a=10;
     char b='A';
     float c=9.19;
     p=&a;
     printf("\nPrinting Integer data %d",(*(int *)p));
     p=&b;
     printf("\nPrinting character data %c",(*(char*)p));
     p=&c;
     printf("\nPrinting float data %f",(*(float *)p));
}
If this article is helpful to you then please like share and comments. thank you


Comments

Popular posts from this blog

Important Announcements(download all my book free)

O LEVEL- INTERNET TECHNOLOGY & WEB DESIGN

Call by Reference with Pointer in C Language part-4-a