Posts

Pattern Printing coding 14

Image
//If you are visiting this post in mobile then, please use desktop site mode //     CODE NO:- 23 Print the below pattern #LOGIC Using two inner loop print the first half of the pattern. Using another two inner loop print the second half of the pattern. For example:  if entered no.of rows are 4 then the first half will contain 4 rows and another half will contain 3 rows. #Program( In C): In    C language we use  ' // '  for Single line comment and /*---*/ for multi line comment #include<stdio.h>// header file for i/p and o/p int main() { int i,j,a=0,b,n,k; printf("\n enter no. of rows:"); scanf("%d",&n); for(i=0;i<n;i++)// loop for printing the upper half of the pattern { for(j=0;j<=i;j++) { printf("*"); } printf("\n"); } for(i=0;i<n-1;i++)// loop for printing the lower half of the pattern { for(j=0;j<n-1-i;j++) { printf("*"); } printf("\n"); } re...

Pattern Printing coding 13

Image
//If you are visiting this post in mobile then, please use desktop site mode //     CODE NO:- 22 Print the below pattern #LOGIC Here we will require two inner loops, one for printing the spaces and another for printing the pattern (numerical values). Take a variable and initialize it the value 0(zero) then in  the second inner loop keep incrementing it by 1. As we can see in the second row we need to print first space then numerical value whereas in the first row we don't need to print any spaces. #Program( In C): In    C language we use  ' // '  for Single line comment and /*---*/ for multi line comment #include<stdio.h>// header file for i/p and o/p int main() { int i,j,a=0,n,k; printf("\n enter the no. of rows:"); scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<i;j++)// for pinting spaces in each row { printf("  ...

Pattern Printing coding 12

Image
//If you are visiting this post in mobile then, please use desktop site mode //    CODE NO:- 21 Print the below pattern                                                                                                                                                     #LOGIC Take two variables and assign it with value (n*n)-(n-1) and 0(zero)  here n means the no. of entered rows and (n*n)-(n-1) is the first element of the pattern. ex: if n is 4 then (n*n)-(n-1) results 13.  Now copy the value (n*n)-(n-1) in other variable and increment it by 1 in the inner loop whereas in the out...

Pattern Printing coding 11

Image
CODE NO:- 20 Print the below pattern #LOGIC Take a variable and assign it with value 0(zero) then keep incrementing it by 1 in the inner loop. #Program( In C): In    C language we use  ' // '  for Single line comment and /*---*/ for multi line comment #include<stdio.h> // header file for i/p and o/p int main() { int i,j,a=0,n; printf("\n enter the no. of rows:"); scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%3d",++a);// %3d is used to display the pattern correctly } printf("\n"); } /* %3d is a format specifier where % means "print the variable here" 3 means "use at least 3 spaces to display, padding as needed" d means integer putting the above sentences together we can say that: "print...

General code 4

Image
CODE NO:- 19 Q) A prime number is a whole number greater than 1, whose only two whole-number factors are 1 and itself. The first few prime numbers are 2, 3, 5, 7, 11 and 13. Given two integers, print the sum of all prime numbers between n1 and n2 (both inclusive). Input The first line of the input contains an integer t, number of test cases next t lines follow with  each line containing two integers n1 and n2 Output For each test case print the answer in a new line. Example Input: 2 1 6 6 6 Output: 10 0 Test Cases: --------------- 1. Valid Input: a) Only integer will be given as input. Constraints: 1 < t <= 10 0 < n1 <= n2 <= 100 2. Invalid inputs: a) Negative number (t, n1, or n2) b) Fraction c) String 3. You should generate output as follows: a) For right output print just the sum to STDOUT without any other text. b) If any error: print 'ERROR' to the STDOUT without any other text. #Program( In C): In  ...