Stuck on multiplication table in C

  • A+
Category:Languages

I'm new to C programming. I was trying to write a program that accepts an integer from user and displays its multiplication table up to 10 multiples. This is my program:

#include <stdio.h>  int main () {         int number;         int count = 1;         int sum;          printf("Enter a number to display its table: ");         scanf(" %i ", &number);          while (count <=10)                 {                     sum = number * count;                     printf("%i x %i = %i/n", number, count, sum);                     count += 1;                 } return 0; } 

Compilation successfully completes, but when I execute the output file, nothing happens, the terminal is stuck at nothing, i've to press ctrl+c to get out..

Stuck on multiplication table in C

 


This is due to the spaces used in your scanf command.

If you replace that with

scanf("%i", &number); 

you get an instant response.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: