CODE NO:- 12 Print the below pattern #LOGIC Take two variables and assign it with value (((n*(n+1))/2)+2)-(n-1) and 0(zero) here n means the no. of entered rows and (((n*(n+1))/2)+2)-(n-1) is the first element of the pattern. ex: if n is 4 then (((n*(n+1))/2)+2)-(n-1) results 9. Now copy the value (((n*(n+1))/2)+2)-(n-1) in other variable and increment it by 1 in the inner loop whereas in the outer loop decrement it by value (n-i-1). Proceed in the same manner to print the pattern. #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 n,i,k,a,b=0; printf("\n enter the no.of rows:"); scanf("%d",&n); a= (((n*(n+1))/2)+2)-(n-1) ; for(i=0;i<n;i++) { b=a; ...
Easy, have some average level codes
ReplyDelete