Skip to main content

Posts

Showing posts from August, 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 ; }

Reverse a string with strrev() function in C Language

In this C program we will store a String in memory and Reverse it with the help of strrev() fuction. The String will be given by the User. Learn about different string functions and their use: Different String Functions input: The String. output: The Reversed String will be printed on the screen. CODE----> #include<stdio.h> #include<string.h> int main () { char str [ 100 ]; printf ( "Please, Enter the String : " ); gets ( str ); puts ( strrev ( str )); return 0 ; } Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Please, Enter the String : ProgramJoy.blogspot.com moc.topsgolb.yoJmargorP -------------------------------- Process exited after 34.15 seconds with return value 0 Press any key to continue . . . Images for better understanding :

Reverse a string without strrev() in C Language

In this C program we will store a String in memory and Reverse it. The String will be given by the User. Learn about different string functions and their use: Different String Functions input: The String. output: The Reversed String will be printed on the screen. CODE----> #include<stdio.h> #include<string.h> int main () { int n , i = 0 ; char temp , str [ 100 ]; printf ( "Please, Enter the String : " ); gets ( str ); n = strlen ( str ); while ( i < n ) { temp = str [ i ]; str [ i ]= str [ n - 1 ]; str [ n - 1 ]= temp ; i ++; n --; } puts ( str ); return 0 ; } Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Please, Enter the String : Welcome to your programming home emoh gnimmargorp ruoy ot emocleW -------------------------------- Process exited after 20.64 seconds with return value 0 Press any key to continue . . . Images for better understandin...

Storing a String in C-Language

In this C program we will store a String in memory. The String will be given by the User. Learn about different string functions and their use: Different String Functions input: The String. output: The String will be printed on the screen which is given by the user. CODE----> #include<stdio.h> int main () { char str [ 100 ]; printf ( "Please, Enter the String : " ); gets ( str ); printf ( "The String is: " ); puts ( str ); return 0 ; } Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Please, Enter the String : Welcome to ProgramJoy ! The String is: Welcome to ProgramJoy ! -------------------------------- Process exited after 19.75 seconds with return value 0 Press any key to continue . . . Images for better understanding :

Queue using Linked List in C-Language

In this C program we will perform Linear Queue operations using Linked List . input: The Choice(i.e Data insert, Data delete and Display) & The Number (integers) (i.e. for Data insert) (15,10,128 etc.) output: The Operations will be excecuted as choosen by the user. CODE----> #include<stdio.h> #include<stdlib.h> #include<malloc.h> typedef struct node { int data ; struct node * next ; } node ; node * rear = NULL ,* front = NULL ; void qinsert ( int value ) { node * getnode ; getnode =( node *) malloc ( sizeof ( node )); getnode -> data = value ; if ( rear == NULL ) { rear = getnode ; rear -> next = NULL ; front = rear ; } else { rear -> next = getnode ; rear = getnode ; rear -> next = NULL ; } } void qdelete () { node * delnode ; delnode = front ; if ( delnode == NULL ) printf ( "\n No elements to delete. Empty Queue." ); else if ( front == rear ) { printf ( "\n The val...

Stack using Singly Linked List in C-Language

In this C program we will perform Stack operations using Linked List . input: The Choice(i.e Push,Pop,Display) & The Number (integers) (i.e. for Push) (15,10,128 etc.) output: The Operations will be excecuted as choosen by the user. CODE----> #include<stdio.h> #include<stdlib.h> #include<malloc.h> typedef struct node { int data ; struct node * next ; } node ; node * top ; void push ( int data ) { node * head ,* afterhead ; head =( node *) malloc ( sizeof ( node )); if ( head == NULL ) { printf ( "\nMemory cant be allocated." ); exit ( 0 ); } head -> data = data ; head -> next = NULL ; if ( top == NULL ) top = head ; else { afterhead = top ; top = head ; head -> next = afterhead ; } } void pop () { node * ptr ; if ( top == NULL ) { printf ( "\nStack Underflow." ); exit ( 0 ); } else { ptr = top ; printf ( "\n%d is Popped from Stack." , ptr -> data )...

print the following pattern in C-Language

In this C -program we will Print the following Pattern made of numbers(1,2,3 etc). The no. of rows will be taken from the user. 1 2 3 4 5 6 7 8 9 10 input: The number of rows. output: The Pattern will be printed on the screen in the given range. CODE----> #include<stdio.h> #include<stdlib.h> int main () { int row , col , num = 1 , n ; printf ( "Enter number of rows: " ); scanf ( "%d" ,& n ); if ( n <= 0 ) { printf ( "Wrong input." ); exit ( 0 ); } for ( row = 1 ; row <= n ; row ++) { for ( col = 1 ; col <= row ; col ++) { printf ( "%d " , num ); num ++; } printf ( "\n" ); } return 0 ; } Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Enter number of rows: 3 1 2 3 4 5 6 -------------------------------- Process exited after 5.664 seconds with return value 0 Press any key to continue . . . Images for ...

print the following pattern in C-Language

In this C -program we will Print the following Pattern made of asterisk(*). The no. of rows will be taken from the user. ***** **** *** ** * input: The number of rows. output: The Pattern will be printed on the screen in the given range. CODE----> #include<stdio.h> #include<stdlib.h> int main () { int i , j , k , n , space = 0 ; printf ( "Please, Enter the no. of rows : " ); scanf ( "%d" ,& n ); if ( n <= 0 ) { printf ( "Wrong input." ); exit ( 0 ); } for ( i = n ; i > 0 ; i --) { for ( k = space ; k > 0 ; k --) printf ( " " ); for ( j = i ; j > 0 ; j --) printf ( "*" ); space = space + 1 ; printf ( "\n" ); } return 0 ; } ~ The Space variable is actually used for new line. Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Please, Enter the no. of rows : 5 ***** **** ...

Square made of asterisk(*) in C-Language

In this C -program we will Print the Square made of asterisk(*). The no. of rows will be taken from the user. * * * * * * * * * input: The number of rows. output: The Pattern will be printed on the screen in the given range. CODE----> #include<stdio.h> #include<stdlib.h> int main () { int i , j , n ; printf ( "Please, Enter the no. of rows : " ); scanf ( "%d" ,& n ); if ( n <= 0 ) { printf ( "Wrong input." ); exit ( 0 ); } for ( i = 0 ; i < n ; i ++) { for ( j = 0 ; j < n ; j ++) { printf ( " * " ); } printf ( "\n" ); } return 0 ; } Download the C-Program file of this Program. Don't just read, run on your pc !!! RESULT : Please, Enter the no. of rows : 10 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ...

C-Program of Singly Linked List

In this C program we will perform operations on Singly Linked List ( i.e: Data insert Operations(at begining or at end or at any position), Data remove Operation(from begining or from end or from any position), Data Reverse 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, reverse 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<malloc.h> #include<stdlib.h> typedef struct node { int data ; struct node * next ; } node ; node * head = NULL ; node * getnode ( int x ) { node * n ; n =( node *) malloc ( sizeof ( node )); n -> data = x ; n -> next = NULL ; return ( n ); } void createlist () { int x ; ...