Skip to main content

Posts

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

A Pattern using Asterisk(*) in C-Language

In this C -program we will Print a pattern using Asterisks(*). The no. of rows will be taken from the user. In the first Row the no. of spaces will be (n-1) [Here, we considered that, the user entered n no. of rows as input],and then a * . In the 2nd Row the number of Spaces will be decreased and the no. of * will be increased by 1. In that way, the last Row(n th row) have no Spaces and have all(n) * . ----* ---** --*** -**** ***** ► Here, - sign is used as Space for better understanding. input: The no. of Rows. output: The Pattern will be printed on the screen in the given range. CODE----> #include<stdio.h> int main () { int i , j , k , n ; printf ( " Please, Enter the no. of Rows : " ); scanf ( "%d" ,& n ); for ( i = 1 ; i <= n ; i ++) { for ( j = n ; j > i ; j --) { printf ( " " ); } for ( k = 1 ; k <= i ; k ++) { printf ( "*" ); } printf ( "\n&q

Inverted Half-Pyramid using Asterisk(*) in C-Language

In this C -program we will Print the inverted "Half-Pyramid" using Asterisks(*). The no. of rows will be taken from the user. ***** **** *** ** * input: The number of the 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 ); if ( n <= 0 ) { printf ( "\n Please, Enter a Positive number." ); printf ( "\n Wrong Input." ); exit ( 0 ); } for ( i = n ; i >= 1 ; i --) { for ( j = i ; j >= 1 ; j --) { printf ( "*" ); } printf ( "\n" ); } return 0 ; } Download the C-Program file of this Program. Don't just read, write it, run it..... RESULT :

Half Pyramid Using ABC (alphabets) in C-language

In this C -program we will Print the "Half-Pyramid" using Alphabet(A,B,C). The range will be taken from the user. A AB ABC ABCD ABCDE input: The Range(a letter). The input letter must be in Capital, as we created this C-Program for Capital letters. output: The Pattern will be printed on the screen in the given range. CODE----> //Half-Pyramid using Alphabets #include<stdio.h> int main () { int j = 0 ; char alphabet = 'A' , i = 'A' , n ; printf ( " Please, Enter a Capital Letter (no small Letter) : " ); scanf ( "%c" ,& n ); while ( i <= 'Z' ) //checking, entered letter is capital. { if ( i == n ) { j = 1 ; break ; } else i ++; } if ( j == 0 ) { printf ( "\n Wrong input Entered." ); exit ( 0 ); } //Checking Ends here. for ( i = 'A' ; i <= n ; i ++)