adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C and C++ to print arrow pattern

Program in C and C++ to print arrow pattern 

      *
    *
  *
*  *  *  *
  *
    *
      *
C Program
 #include<stdio.h>
 int main(){
 	int i, j;
 	for(i = 1; i <= 7; i++){
 	  for(j = 1; j <= 4; j++){
 	  	if(i <= 3){
 	  	  if(i == 5 - j)
 	  	     printf(" *");
 	  	  else
 	  	     printf("  ");
		 }
		else if(i == 4)
		  printf(" * ");
	        else{
		  if(i == 3 + j)
 	  	     printf(" *");
 	  	  else
 	  	     printf("  ");
		}
	   } 
	  printf("\n");
	}
    return 0;
 }
C++ Program
#include<iostream>
 int main(){
 	int i, j;
 	for(i = 1; i <= 7; i++){
 	  for(j = 1; j <= 4; j++){
 	  	if(i <= 3){
 	  	  if(i == 5 - j)
 	  	    std::cout<<" *";
 	  	  else
 	  	    std::cout<<"  ";
		}
		else if(i == 4)
		    std::cout<<" * ";
	        else{
		   if(i == 3 + j)
 	  	     std::cout<<" *";
 	           else
 	  	     std::cout<<"  ";
	      }
	    } 
	std::cout<<"\n";
     }
    return 0;
 }
Output :-

  

Output


Related Programs

Post a Comment

0 Comments