Friday, 12 June 2020

Count divisible number in given range C Language

Q : Write a C Program to print and count all numbers between 1 to 100 divisible by 11.


Answer : 



#include<stdio.h>
#include<conio.h>
/*##########################
     Girfa Student Help
     Count & print all number 1 to 100
     divisible by 11
  ##########################*/

Actual and former parameter C Language


As we know C language is building block of function. Anything done in C language by function. Function can take argument. There are two types of argument given below.

  • Argument pass while calling is actual
  • Argument while declaring function is former


#include<stdio.h>
#include<conio.h>
/*##########################
     Girfa Student Help
     Formal and actual parameter program
  ##########################*/
int sum(int,int);
void main()
{
     int a,b,c;
     clrscr();
     a=10;
     b=20;
     c=sum(a,b);   /* a and b are actual parameter */
     printf("\n\tA=%d\n\tB=%d\n\tSum=%d",a,b,c);
     getch();
}
int sum(n1,n2) /* n1,n2 are formal parameter */
{
     return n1+n2;
}

In the function main in the example above, a, and b are all actual parameters when used to call calculate sum function. On the other hand, the corresponding variables in sum_funcation definition (namely n1, n2) are all formal parameters because they appear in a function definition.



Difference between function definition and function declaration

Difference between  function definition and function declaration

DECLARATION
DEFINITION
A variable or a function can be declared any number of times
A variable or a function can be defined only once
Memory will not be allocated during declaration
Memory will be allocated
int f(int);
The above is a function declaration. This declaration is just for informing the compiler that a function named f with return type and argument as int will be used in the function.
int f(int a)
{
  return a;
}
The system allocates memory by seeing the above function definition.

Decimal to Binary conversion C language

Q : Write a C Program using function to print equivalent binary number of decimal number input by keyboard ?

Answer : 

#include<stdio.h>
#include<conio.h>
/*##########################
     Girfa Student Help
     Decimal to Binary conversion
  ##########################*/
void main()
{
     int d,b,ar[10],i;
     clrscr();
     printf("Enter number> ");
     scanf("%d",&d);
     i=0;
     while(d>0)
     {
          ar[i]=d%2;
          d=d/2;
          i++;
     }
     i--;
     while(i>=0)
     {
          printf("\t%d",ar[i]);
          i--;
     }
     getch();
}