Skip to main content

How to get division of 2 integer number in c language. || division program in c language.

  How to get a division of 2 numbers in c language. Division of two integer number in c Division of 2 integer number:     here we want to get a division of 2 number so for that we have to take 3 variable  1st is for Dividend, 2nd is for divisor and, 3rd is for an answer.     the simple logic is  a= b/c.     here variable "a" get value which is the division of b and c in other words we can say that a is the answer of b divide by c. we show you to way to get an answer. 1) In this way, we have to just take the answer in 3rd variable, and then after we have to print that variable. hear we take div as answer variable. Example:: #include<stdio.h> #include<conio.h> void main() {     int a,b,div;     clrscr();     printf("\nWelcome,CoderFact\n---------------Division---------------");     printf("\nEnter a First Number(Divisior) :");     scanf("%d",&a);     printf("\nEnter a S...

How to Newline in C Language || Without use \n newline in c

What is the use of \n keyword in C language?

use of \n (newline)

        In C Language "\n" is a special character. "\n" is used to send a pointer to the next line. So for avoiding a mixer of 2 sentences in output, we use \n, which makes an output or execution of code from the new line, basically, we use \n to print the output in the next line of an output screen in C language. 

form example we can understand batter, hear we explain you by 2 different programs that how \n in work.

Example ::

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

void main()
{
 clrscr();
 printf("Welcome To CoderFact.");
 printf("It's All about IT(Information Technology) fact.");
 printf("This is Example of c Language.");
 getch();
}


OUTPUT::









hear you see that without \n the output is not proper. hear we print different sentences in the new printf function but printf function is not used to give a new line in the output.

so for a new line, we have to right \n to get output in the new line.


Example ::


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

void main()
{
 clrscr();
 printf("Welcome To CoderFact.");
 printf("\nIt's All about IT(Information Technology) fact.");
 printf("\nThis is Example of c Language.");
 getch();
}

OUTPUT::






hear we use a \n in printf function so we get output in new line. so from this example, you may learn that how \n works in the c language and how it properly gives output.




ANOTHER WAY TO DECLARE \n.


    there are many other ways to declare \n with a different keyword or special character.


 let's see 1st one:

        we can also write  x0A instead of \n. basically, x0A is an ASCII value of \n in hexadecimal (10 decimal) so you can use anywhere this x0A in the printf statement to print a text from a new line.

Example ::


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

void main()
{
 clrscr();
 printf("Welcome To CoderFact.");
 printf("\x0AIt's All about IT(Information Technology) fact.");
 printf("\x0AThis is Example of c Language.");
 getch();
}

OUTPUT::



in this output, you see that x0A is working the same as the same \n work. so you can also write x0A instead of \n.



2nd way to declair \n:

Use %c to print a new line in printf with value 10 or x0A.
in this case, usually %c is used to get character but hear we pass ASCII value of  \n  so %c is work like \n and print output from the new line.
  
Example ::

#include<stdio.h>

#include<conio.h>

void main()
{
 clrscr();
 printf("Welcome To CoderFact.");
 printf("%cIt's All about IT(Information Technology) fact.",10);
 printf("%cThis is Example of c Language.",10);
 getch();
}


OUTPUT::



hear we write %c in printf statement and pass 10 as ASCIIvalue so its work like a \n. 




Example2::

in this case, usually %c is used to get character but hear we pass the value as  \n  so %c is work like \n and print output from the new line.
  


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

void main()
{
 clrscr();
 printf("Welcome To CoderFact.");
 printf("%cIt's All about IT(Information Technology) fact.",'\n');
 printf("%cThis is Example of c Language.",'\n');
 getch();
}


OUTPUT::




hear we write %c in printf statement and pass 10 as ASCIIvalue so its work like a \n. 



Example ::


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

void main()
{
 clrscr();
 printf("Welcome To CoderFact.");
 printf("%cIt's All about IT(Information Technology) fact.",0x0A);
 printf("%cThis is Example of c Language.",0x0A);
 getch();
}


OUTPUT::








Comments

Popular posts from this blog

How to Convert Integer To HexaDecimal and HexaDecimal To Integer in c || 1 line code

   Integer To HexaDecimal Example :: #include<stdio.h> #include<conio.h> void main() {     int no;     clrscr();     printf("\nWelcome,CoderFact");     printf("\nEnter a Integer number : ");     scanf("%d",&no);     printf("Hexadecimal number is :  %x",no);     getch(); } Output :: Output of program  HexaDecimal  To Integer  in c Example :: #include<stdio.h> #include<conio.h> void main() {     int no;     clrscr();     printf("\nWelcome,CoderFact");     printf("\nEnter a  Hexadecimal  number : ");          scanf("%x",&no);     printf("Integer number is :  %d",no);     getch(); } Output ::

How to print folat numbers in c language and what are the formation of float variable.

How to print float number in c language.  Floating numbers are basically real numbers.  if we want to print folat numbers in c language for that we have to take %f as keyword in printf and scanf function.  Example : For scanning: Scanf("%f",&variable name); For printing: Printf("foat num is %f.",variable name); There are Diffrent formats  to print float number in c language. Hear we take 1 example which shows you that if we want to print 2 digit after "." Than we have to just write " .2 " in calling printf sattment.  Example: #include<stdio.h> #include<conio.h> void main() {     float a;     clrscr();     printf("\nWelcome,CoderFact");     printf("\nEnter a number : ");     scanf("%f", &a);     printf("Your entered a number is :  %.2f " , a);     getch(); } OUTPUT:: Hear we pass value 12 and we get output  12.00 this thing is occur due to we take input as float nu...

Useful Formula for Programmar

  Simple Interest  ::                                     Si =(p* n*r)/100 Area of Square ::                                                          Area =side* side Area of Rectangle ::                                                           Area = length * breadth Area of Right angled triangle ::                                               Area =(...