Star Pyramid in C
This is a basic program for star pyramid in C programming language
#include<stdio.h>
#include<stdlib.h>
#define USAGE "Usage : pyramid <rows>\n"
int main(int argc, char **argv){
if (argc < 2){
printf(USAGE);
return 1;
}
int maxStars = (atoi(argv[1]) *2) -1;
for (int i =1;i <= (atoi(argv[1])*2) - 1 ;i+=2){
int spaces = (maxStars - i)/2;
for(int j =0;j < spaces;j++){
printf(" ");
}
for(int k = 1;k<= i;k++){
printf("*");
}
for(int l = 0;l < spaces;l++){
printf(" ");
}
printf("\n");
}
return 0;
}
Comments
Post a Comment