Q1. Write A C Program That Reads The Side Size Between 1 and 10 Od A Square and Prints A Hollow Square Using Hash (#) Character?

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Q1.

Write a C program that reads the side size between 1 and 10 od a


square and prints a hollow square using hash(#) character?
#include<stdio.h>
int main()
{
int size, i, j;

printf( "Input the size of the square: " );


scanf( "%d", &size );

if(size < 1 || size > 10) {


printf("Size should be in the range 1 to 10\n");
return 0;
}

for(i=0; i<size; i++)


{
for(j=0; j<size; j++)
{
if(i==0 || i==size-1)
printf("#");
else if(j==0 || j==size-1)
printf("#");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Q2. Write a C program which reads an integer (7 digits or fewer) and
count the number of 3s in the given number?
#include<stdio.h>
int count_three( int );
int main()
{
int num;
printf( "Input a number: " );
scanf("%d", &num);
while(num!=0){
no = no/10;
totalDigits ++;
}
If (num>7){
Printf(“Length of the Number must 7 or less than seven”);
}else{
printf("The number of threes in the said number is %d\n", count_three(num) );
}
return 0;
}

int count_three(int num)


{
int ctr = 0;
int remainder;

while(num > 0) {
remainder = num % 10;
num /= 10;

if(remainder == 3)
ctr++;
}

return ctr;
}

You might also like