You are an elementary school teacher and explaining multiplication to students.
You are going to use multiplication by 3 as your example.
The program you are given takes N number as input. Write a program to output all numbers from 1 to N, replacing all numbers that are multiples of 3 by "*".
Sample Input
7
Sample Output
12*45*7
Loading
Siddhant pandaPosted Oct 25, 2021, 5:04 AM
in this airtcle i explain how i did
step1- Read number from Console.
step2-loop with in range of 1 to Number
step3-check if else conditon from starting range if number divisible by 3 then replace by * otherwise same number.
step4- after that add enter number.
step5-print the output
Answer.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp7
{
{
class Program
{
static void Main(string[] args)
{
string repalce = "";
Console.WriteLine("Enter Number:");
int number = Convert.ToInt32(Console.ReadLine());
for(int index=1;index
if(index%3==0)
{
repalce = repalce + "*";
}
else
{
repalce = repalce + index;
}
}
Console.WriteLine(repalce+number);
}
}
}
Sachin SinghPosted Oct 25, 2021, 5:01 AM