Skip to main content

Posts

Showing posts from January, 2019

C programs QnA

Q. If sum of two integer is 14 and if one of them is 8 then find other integer. Ans: Well, this is very simple. Simply, one integer is 8 and sum of two integers is 14. So, we need to subtract the number 8 from their sum of 14 to get the second number. So, the second number is: 14 - 8 = 6 C-Program of this task Code---> #include<stdio.h> int main () { int num1 = 8 , num2 , sum = 14 ; num2 = sum - num1 ; printf ( "The second number is: %d" , num2 ); return 0 ; }

Perfect Numbers in a Range in C-Language

In this C -program we will check the Perfect numbers in a given Range and print them on the screen. The lower range and the upper range will be taken from the user. input: The Lower Range and the Upper Range. output: The Perfect numbers will be printed on the screen in the given range. CODE----> #include<stdio.h> #include<stdlib.h> int perfect ( int x ) { int i , sum = 0 ; if ( x == 0 ) return 0 ; for ( i = 1 ; i <=( x - 1 ); i ++) { if ( x % i == 0 ) sum = sum + i ; } if ( sum == x ) return 1 ; else return 0 ; } int main () { int num , i , lr , ur , check ; printf ( "\n Please, Enter the Lower range : " ); scanf ( "%d" ,& lr ); printf ( "\n Please, Enter the Higher range : " ); scanf ( "%d" ,& ur ); printf ( "\n The Perfect numbers are : " ); for ( i = lr ; i <= ur ; i ++) { check = perfect ( i ); if ( check == 1 ) printf ( " %d " , i

Linear Queue Program in C-Language

In this C program we will perform operations over Linear Queue ( i.e: Data insert Operation, Data remove Operation and display Operation ). The Choice( i.e: data insert,remove or display ) will be made by the user and The Number will be taken from the user( i.e: For Data insert Operation ). input: The Choice(i.e Data insert, remove or display) & The Number (integers) (i.e. for Data insert Operations) (15,10,128 etc.) output: The Operations will be excecuted as choosen by the user. CODE----> #include<stdio.h> #include<stdlib.h> #define MAXSIZE 10 int Q [ MAXSIZE ], front =- 1 , rear =- 1 ; void qinsert ( int x ) { if ( rear == MAXSIZE - 1 ) printf ( "\n Queue is Full." ); else if ( front ==- 1 ) { front = 0 ; rear = 0 ; Q [ front ]= x ; } else { rear ++; Q [ rear ]= x ; } } void qdelete () { if ( front ==- 1 ) printf ( "\n Queue is Empty." ); else if ( front == rear ) { printf ( "

Program Of Stack in C-Language

In this C program we will perform operations over Stack ( i.e: Push Operation, Pop Operation and Display Operation ). The Choice( i.e: Push,Pop or Display ) will be made by the user and The Number will be taken from the user( i.e: For Push Operation ). input: The Choice(i.e Push, Pop or Display) & The Number (integers) (i.e. for Push Operations) (15,10,128 etc.) output: The Operations will be excecuted as choosen by the user. CODE----> #include<stdio.h> #include<stdlib.h> #define MAXSIZE 10 int s [ MAXSIZE ], top =- 1 ; void push ( int x ) { if ( top == MAXSIZE - 1 ) printf ( "\n Stack Overflow." ); else { top ++; s [ top ]= x ; } } void pop () { int temp ; if ( top ==- 1 ) printf ( "\n Stack Underflow." ); else { temp = s [ top ]; printf ( "\n %d is Popped from Stack." , temp ); top --; } } void display () { int i ; printf ( "\n The Stack Elements are...\n" ); if

2's Complement of a number using Bitwise Operator in C-Language

In this C program we will Print the Binary Equivalent of a Decimal Number Using Bitwise Operator and then we will print the 2's Complement of the number on the screen. The Number will be taken from the user. N:B This Program is created for upto 8-bit binary number ( i.e: Range = 0 to 2 8 -1 = 0 to 255 ). input: The Number (integers) (i.e. 15,10,128 etc.) output: The binary equivalent of the decimal number and the 2's complement of the number, will be printed on the screen. CODE----> #include<stdio.h> int main () { int n , i , x ; printf ( " Please, Enter a Number : " ); scanf ( "%d" ,& n ); printf ( "\n The binary equivalent of the number : \n " ); for ( i = 7 ; i >= 0 ; i --) { x = n &( 1 << i ); if ( x == 0 ) printf ( "0" ); else printf ( "1" ); } n =~ n ; n = n + 1 ; printf ( "\n The 2's complement of the number :\n " ); for ( i = 7 ;

1's Complement using Bitwise Operator in C-Language

In this C program we will Print the Binary Equivalent of a Decimal Number Using Bitwise Operator and then we will print the 1's Complement of the number on the screen. The Number will be taken from the user. N:B This Program is created for upto 8-bit binary number ( i.e: Range = 0 to 2 8 -1 = 0 to 255 ). input: The Number (integers) (i.e. 15,10,128 etc.) output: The binary equivalent of the decimal number and the 1's complement of the number, will be printed on the screen. CODE----> #include<stdio.h> int main () { int n , i , x ; printf ( " Please, Enter a Number : " ); scanf ( "%d" ,& n ); printf ( "\n The binary equivalent of the number : \n " ); for ( i = 7 ; i >= 0 ; i --) { x = n &( 1 << i ); if ( x == 0 ) printf ( "0" ); else printf ( "1" ); } n =~ n ; printf ( "\n The 1's complement of the number :\n " ); for ( i = 7 ; i >= 0 ; i