beautiful stars pattern based on inputted number-asr
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
int main()
{
char a[20],n[10];
int num[10],x=0;
int i=0,big=1,j;
while(1){
a[i]=getchar();
n[0]=a[i]; //assignt into n[0] otherwise will err...coz index start from 0
num[x]=atoi(n);
if(a[i]=='\n'){
break;
}
i++;
x++;
}
big=num[0];
for(i=1;i<x;i++){
if(big<num[i])
{
big=num[i]; //finding big number from input
}
}
for(i=0;i<=big;i++){
for(j=0;j<x;j++){
if(i==big)
{
printf("%d ",num[j]); // print numbers in bottom
}
else
{
if(i>=big-num[j]) printf("* "); //printing stars logic
else printf(" "); //else print only space
}
}
printf("\n");
}
}
Comments
Post a Comment