3.Write a program to find out the how many 9 is present in given input eg:100 to 10000 ?
VINAY KUMAR GUPTA
--looped in SQL, can be done similarly in c# as well declare @min int = 0,@max int=100,@ctr int =0,@nines int = 0,@str nvarchar(10)=''while (@min<=@max) Begin set @str = convert(nvarchar(10),@min) set @nines = @nines + (len(@str)-len(replace(@str,'9',''))) set @min=@min+1 End select @nines
public static void Main() { int a = 100; int b = 10000; int count = 0; int c = 0; int x = 0; for (int i = a; i <= b; i++) { c = i; while (c != 0) { x = c % 10; c = c / 10; if (x == 9) { count++; } } } Console.WriteLine(count); }
public static void Main() {int a = 100;int b = 10000;int count = 0;int c = 0;int x = 0;for (int i = a; i <= b; i++){c = i;while (c != 0){x = c % 10;c = c / 10;if (x == 9){count++;}}}Console.WriteLine(count); }