C Program to Print Subtraction of Given Two Numbers

Ex: Write a C program to print Subtraction of given two number. How to print subtraction of given two numbers. C Program to print subtraction of two numbers.

Input from user:
Enter the value of a and b:
50 20

Expected output:
Subtraction is: 30



  Step by step logic of the given program:


1. Accept two numbers from user declare variables say a and b.

2.subtract b from a(a-b) and store subtraction in variable c.

3. Print Subtraction on the output screen:
printf("Subtraction is %d",c);





  C program to print subtraction of given two numbers :


/***C program to print subtraction of two numbers***/

#include<stdio.h>
void main()
{
 int a,b,c;//declear three intiger type variables
 
 //Get input from user
 printf("Enter the value of a and b\n");
 scanf("%d%d",&a,&b);

 c=a-b;//subract b from a
 
//display subtraction
 printf("Subtraction is %d",c);
}



Above program shows the following output:


Basic C Programming Exercises and Examples with Solution

C programming language is easy to learn... Although numerous computer languages are used to write computer applications, the computer programming language C is the most popular language worldwide.

C programming language is best and interested to know how a computer program works internally.


    Quick Links:

-> Input/output functions.
 -> C variable declaration and initialization.


If you are a beginner or interested in programming or you want to learn C programming then codeforhunger is for you.
I am sure you will find these exercises and examples interesting and useful to gain your C programming language knowledge.


Here, we will start from the basics to advance. With a lot of exercises and examples with their solutions.



  Basic C Programming Exercises and Examples:


 Feel Free to share your doubts in the comment section given below... :)



Bitwise Operators In C, Exercises and Examples with Solution

In the C Programming language, operations can be performed on a bit level using bitwise operators. We use bitwise operators to manipulate data  at its lowest bit level. bitwise operators works on each bit of the data.


Definition: A bitwise operator is an operator used to perform bitwise operations on bit patterns or binary numerals that involve the manipulation of individual bits.
Bitwise operators are used in communication stack.


There are six bitwise operators are in C programming:

Bitwise operators in C, exercises and examples with solution


Above table shows six bitwise operators used in C programming language.

  Bitwise Operators In C:


  1. Bitwise AND
  2. Bitwise OR
  3. Bitwise XOR
  4. Bitwise Complement
  5. Bitwise left shift
  6. Bitwise right shift

For more details:- bitwise operators .



  Bitwise operators in C exercise examples:



1. Write a C program which perform bitwise AND operation.

2. Write a C program which perform bitwise OR operation.

3. Write a C program which perform bitwise XOR operation.

4. Write a C program which perform bitwise Compliment(~) operation.

5. Write a C program which perform bitwise left-shift(<<) operation.

6. Write a C program which perform bitwise right-shift(>>) operation.

7. C program to print given number is even or odd using bitwise operators.





Types Of Jobs In IT Field (Part-time Jobs)

In this article, we will look at the different types of jobs available in the IT industry and explore part-time job opportunities. We will discuss the roles, skills needed, and the benefits of working part-time in IT. You can find a variety of roles in areas like technical support, web development, cybersecurity, and data analysis. These jobs cater to different interests and skills.


It jobs, It part time jobs
Photo by Jason Goodman on Unsplash



  Jobs In IT

There are different types of jobs available in IT industry some of that are...
  1. Mobile application developer..
  2. Web developer...
  3. Software engineer...
  4. Full-stack developer
  5. Database administrator...
  6. IT consultant...
  7. Game developer (programming and designing in gaming).
  8. Data Scientist
  9. Cyber security
  10. Web administrator and many more......


  Which part-time job is best?

If you are an IT student or a programmer, doing an internship in an IT company is the best part-time job for you. Additionally, you can also pursue other opportunities such as...
  • IT Intern
  • Software Tester
  • Freelance web developer
  • Freelance IT consultant
  • IT support Technician
  • Content writer/Editor
  • Home Tutor

These are the part-time jobs you can do while pursuing your studies. Engaging in part-time IT jobs not only allows you to earn income but also enables you to develop a deeper understanding of the industry, gain hands-on experience, and build a professional network. Additionally, focusing on programming as a student can lay a solid foundation for a successful career in programming and open doors to a wide range of opportunities.

C Program To Print Square star Pattern

Ex: Write a C Program To Print Square star Pattern. How to write a C Program To Print Square star Pattern. C Program To Print Square star Pattern.


Input from user:
Enter number: 5

Expected output:
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *




   Step by step logic to print square star pattern:

1. First accept input(number) from user  which shows how many rows and column's do you want to print.

2. After that use one external for loop which will interate from 0 to no-1 and it shows rows in your square pattern:
for(i=0;i<no;i++)

3. Then use one another for loop inside the above for loop which prints the number of columns:
for(j=0;j<no;j++)

4. Inside the inner loop means inside the second for loop print * with one space like this:
printf("* ");

5.  After that use \n for new line(new row).





   Program to print sqaure star pattern:



#include<stdio.h>
void main()
{
int i,j,no;

printf("Enter the number:\n");
scanf("%d",&no);

for(i=0;i<no;i++)
{
for(j=0;j<no;j++)
{
printf("* ");
}
printf("\n");
}
}



Above Program show's the following output:

C Program To Print Square star Pattern




C Program To Print inverted Pyramid star pattern

Ex: Write a C Program To Print inverted Pyramid star pattern. How to write a C Program To Print inverted Pyramid star pattern. C Program To Print inverted Pyramid star pattern.


Input from user:
Enter the number:
7

Expected output:
*******
 ******
  *****
   ****
    ***
     **
      *
       



   Step by step logic of the given program:

1. Accept input(number) from user which shows number of rows, declare variable say no.

2. Run one outer  loop from 1 to no:
  for(i=1;i<=no;i++)

3. To print spaces run another for loop from 1 to i-1:
for(j=1;j<i;j++)
  printf(" ");
    

4. To print star use another one inner for loop from i to no:
for(k=i;k<=no;k++)
   printf(" *");
    

5. For new row, move to next line using \n.





   Program to print inverted pyramid star pattern:

#include<stdio.h>
void main()
{
int no,i,j,k;

printf("Enter the no\n");
scanf("%d",&no);

for(i=1;i<=no;i++)
{
for(j=1;j<i;j++)
printf(" ");

for(k=i;k<=no;k++)
printf(" *");

printf("\n");
}

}


Above program shows the following output:


C Program to print inverted pyramid star pattern



C Program To Print Given Number Is Even or Odd

EX: What is logic to print given number is even or odd. C program to print given number is even or odd. how to print given number is even or odd.


Logic to print given number is even or odd:


1. In this Program we will take number from user using no variable. 


2. Next we will check it is even or odd using the (no%2==0).

3. Means if no is complete divisible by 2 then it is even otherwise number is odd.

4. Display this output using input/output function.



C  Program To Print Given Number Is Even or Odd: 


#include<stdio.h>

void main()
{
int no; 

printf("Enter the number\n");

scanf("%d",&no);

if(no%2==0)
printf("Given number is Even\n");

else
printf("Given number is Odd\n");

}


Above Program's show's the following output:



C  Program To Print Given Number Is Even or Odd



C Program To Swap Two Numbers Without Using Third Variable

Ex: write a C program to swap two numbers without using third variable. How to swap two numbers without using third variable. C PROGRAM to swap two numbers without using third variable.


In below code we will swap values of two variable without using third variable.
Here, we will use the addition and subtraction for swap two variable's. 



C  Program To  Swap Two Numbers Without Using Third Variable:


#include<stdio.h>
void main()
{

 int a,b;

 printf("Enter the value of a and b\n");
 scanf("%d%d",&a,&b);

 printf("values of a & b before swap\na=%d b=%d",a,b);

 a=a+b;
 b=a-b;
 a=a-b;

 printf("\nvalues of a & b after swaping\na=%d b=%d",a,b);

}



Above Program's show's the following output:



C  Program To  Swap Two Numbers Without Using Third Variable




C Program To Print Factorial Of 1 to n Number's

Ex: What is the logic to print factorial of 1 to n Number's. How to print factorial of 1 to n numbers. C program to print factorial of 1 to n number.

Input from user:
Enter the number: 5

Expected output:
Factorial of 1 is: 1
Factorial of 1 is: 2
Factorial of 1 is: 6
Factorial of 1 is: 24
Factorial of 1 is: 120




  Logic to print factorial of 1 to n number's:


1. Accept input number from user.

2. Run outer for loop from 1 to no:
for(i=1;i<=no;i++)

3. Make f=i.

4. Run inner for loop from i to 2 and inside the inner for loop add given factorial logic:
for(j=i;j>1;j--)
 {
      f=f*(j-1);
 }

5. After that outside the inner loop print value of f means factorial numbers.





  C  Program To Print Factorial Of 1 to n Number's:


#include<stdio.h>
void main()
{
 int i,j,no,f;
 
    printf("Enter the number:\n");
    scanf("%d",&no);
   
    for(i=1;i<=no;i++)
    {
     f=i;
     for(j=i;j>1;j--)
     {
        f=f*(j-1);
     }
     printf("Factorial of %d is = %d\n",i,f);
    }
}


Above Program show's the following output:

C  Program To Print Factorial Of 1 to n Number's





Mostly Asked 25 C Programming Apti MCQ Questions

In this article, I will share some frequently asked C programming aptitude questions.
 

1. Which header file  do you need  to include to use  typecasting?

  • <stdin.h>
  • <ctype.h>
  • <math.h>
  • none of these


2. # include is called____________

  • Preprocessor Directive
  • Inclusion Directive
  • File inclusion directive
  • none of these


3A local  variable  is store in_______

  • code segment
  • stack  segment
  • heap segment
  • none of these


4. An exception is ________

  • Runtime Error
  • Compile Error
  • Logical Error
  • None of the above




5Which of the  following is valid expression for assigning the value to the variable?

  • a==b
  • a:=b
  • a=b
  • none of the above


6Which of the following is not a reserve keyword for c?

  • auto
  • case
  • main
  • Register


7Which of the following is not correct variable type

  • float
  • real
  • double
  • int


8. Every function  in c is followed by

  • parenthesis
  • square brackets
  • curly braces
  • All of the above


9. In command  line argument the parameter argc passed to main is of______ datatype

  • float
  • int
  • string
  • double


10. What will be the following code's output if choice = 'R'?

switch(choice)
{
   case 'R' : printf("RED");
   case 'W' : printf("WHITE");
   case 'B' : printf("BLUE");
   default  : printf("ERROR");break;
}


  • RED
  • RED WHITE BLUE ERROR
  • RED ERROR  
  • ERROR


11What is the correct value to return to the operating system on the successful  completion of key program?
  • -1
  • 1
  • 0
  • It does not return any value




12. An array of similar data types which themselves are a collection of dissimilar data types are___

  • Linked lists
  • Trees
  • Array of structure
  • All of the above


13. What will happen after compiling and running following code?

main()
{
     printf("%p", main);
}

  • Error
  • Will make an infinite loop
  • Some address will be printed.
  • None of these.


14. What will be the output if you will compile and execute the following C code?

#include<stdio.h>
int main()
{
int a=5;
float b;
printf(“%d”,sizeof(++a+b));
printf(“%d”,a);
return 0;
}

  • 26
  • 46
  • 25
  • 45


15How many times do while loop guaranteed to loop?

  • 0
  • infinity
  • 1
  • variable


16int a[5] = {1,2,3}
What is the value of a[4]?

  • 3
  • 1
  • 2
  • 0


17. Which of the following operator can be used to access value at address store in a pointer variable...

  • *
  • #
  • &&
  • @


18Which  conversion  is  not possible...

  • int to float
  • float to int
  • char to float
  • All of the above is possible


19What will be the output of the program ?

#include<stdio.h>
void main()
{
    printf(5+"Good Morning");
}


  • Good Morning
  • M  
  • Good
  • Morning


20. Program are converted into machine language with the help of ____

  • an Editor
  • a compiler
  • an operating system
  • none of these


21The  correct  order of  evaluation for the expression “z=x+y*z/4%2-1”


  • */%=+-
  • /*%-+=
  • -+=*%/
  • */%+-=


22. Which of the following function disconnected the stream  from the file pointer?

  • fclose()
  • remove()
  • fremove()
  • file pointer to be set to null


23To flush the memory used by memory n allocation functions, we  use______ function.

  • dealloc()
  • erase()
  • clear()
  • free()


24Which of the following adds one string to end of the  another

  • append()
  • stringadd()
  • strcat()
  • stradd()


25. What will be the output of the given program?

#include<stdio.h>
void main()
{
    int a=11,b=5;
    if(a=5) b++;
    printf("%d %d", ++a, b++);
}

  • 12 7
  • 5 6
  • 6 6
  • 6 7




Answer's:

1-d                                                            
2-a                                                            
3-b                                                            
4-a                                                            
5-c                                                            
6-d                                                            
7-b                                                            
8-a                                                            
9-b                                                            
10-b                                                          
11-c                                                          
12-c                                                          
13-c                                                          
14-d                                                          
15-c                                                          
16-d                                                          
17-a                                                          
18-d                                                          
19-d                                                          
20-b                                                          
21-d                                                          
22-a                                                          
23-d                                                          
24-c                                                          
25-c