Skip to main content

Posts

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

Print the following Pattern in C Language

In this C -program we will Print the following Pattern made of 1 and 2 . The no. of rows will be taken from the user. 1 12 121 1212 12121 input: The number of rows. output: The Pattern will be printed on the screen in the given range. CODE----> #include<stdio.h> int main () { int i , j , n ; printf ( "Please,Enter the no. of rows: " ); scanf ( "%d" ,& n ); for ( i = 1 ; i <= n ; i ++) { for ( j = 1 ; j <= i ; j ++) { if ( j % 2 != 0 ) printf ( "1" ); else printf ( "2" ); } 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: 7 1 12 121 1212 12121 121212 1212121 -------------------------------- Process exited after 1.527 seconds with return value 0 Press any key to continue . . . Images for better understanding :

Print the following Pattern in C Language

In this C -program we will Print the following Pattern made of A and B . The no. of rows will be taken from the user. A AB ABA ABAB ABABA input: The number of rows. output: The Pattern will be printed on the screen in the given range. CODE----> #include<stdio.h> int main () { int i , j , n ; printf ( "\nPlease,Enter the no. of rows: " ); scanf ( "%d" ,& n ); for ( i = 1 ; i <= n ; i ++) { for ( j = 1 ; j <= i ; j ++) { if ( j % 2 != 0 ) printf ( "A" ); else printf ( "B" ); } 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 A AB ABA ABAB ABABA ABABAB ABABABA ABABABAB ABABABABA ABABABABAB -------------------------------- Process exited after 5.282 seconds with return value 0 Press any key to continue . . . Images for better unders...

Matrix Multiplication in C Language

In this C program we will multiply two matrices and print the result on the screen.The elements of the matrices will be taken from the user. input: The elements of matrices. output: The Multiplication of the two matrices. CODE----> #include <stdio.h> void input ( int first [ 10 ][ 10 ], int second [ 10 ][ 10 ], int r1 , int c1 , int r2 , int c2 ) { int i , j ; printf ( "\nEnter elements of matrix 1:\n" ); for ( i = 0 ; i < r1 ; i ++) { for ( j = 0 ; j < c1 ; j ++) { printf ( "Enter data: " ); scanf ( "%d" ,& first [ i ][ j ]); } } printf ( "\nEnter elements of matrix 2:\n" ); for ( i = 0 ; i < r2 ; i ++) { for ( j = 0 ; j < c2 ; j ++) { printf ( "Enter data: " ); scanf ( "%d" ,& second [ i ][ j ]); } } } void multiply ( int first [ 10 ][ 10 ], int second [ ...

Matrix(3*3) Addition in C-Language

In this C program we will add two matrices(3*3) and print the result on the screen.The elements of the matrices will be taken from the user. input: The elements of matrices(3*3). output: The Sum of the two matrices. CODE----> #include<stdio.h> int main () { int mat1 [ 10 ][ 10 ], mat2 [ 10 ][ 10 ], mat3 [ 20 ][ 20 ], i , j ; printf ( "Please,Enter the first matrix--->> " ); for ( i = 1 ; i <= 3 ; i ++) { for ( j = 1 ; j <= 3 ; j ++) { printf ( "\nPlease,Enter data: " ); scanf ( "%d" ,& mat1 [ i ][ j ]); } } printf ( "\n\nPlease,Enter the second matrix--->> " ); for ( i = 1 ; i <= 3 ; i ++) { for ( j = 1 ; j <= 3 ; j ++) { printf ( "\nPlease,Enter data: " ); scanf ( "%d" ,& mat2 [ i ][ j ]); } } printf ( "\n\nThe sum of the matrices --->> \n" ); for ( i = 1 ; i <= 3 ; i ++) { for ( j = 1 ; j <= 3 ; j ++)...

The Dice Game in C-Language

The Dice Game Description: The Dice Game is the result of different and innovative thinking. The idea is to play a game, made by a simple code in C-Language. No graphics, just a simple game. Nothing more to say. Simply, download the code, compile it and start playing. The download link is given below: Download the C-Program file of this Game.             Compile and Play Rules : 1.Every Player gets 100$. 2. Every Player bet 10$ on a number. 3. Dice will be thrown. A random number will generate. 4. The closest bet number to the dice will win. 5.If both players bet the same number, no prize. Better Luck, Next time !! 6. If no money left, then you have lost. 7. The last Player with money, WINS !!! 8. In the Best of 3 match, two-player(s) will be fighting for only three rounds. The major winner of those three rounds will win. However, if both players win only 1 round or no round, then it will call a ...