+ 3
How to take input from user multiple times using while loop??
I want to take number from user Bhai koi madat kr do hum user se bar bar input lena chahte he https://code.sololearn.com/cHC09zCXblKk/?ref=app
10 Respostas
+ 1
/*
it will not work at Sololearn,
because Sololearn takes all the inputs at the beginning.
to make it works at Sololearn, you can make an array to store the tables you want, then get the multiplications.
https://code.sololearn.com/cCp6o92r4o02/?ref=app
example on inputs:
3
5
10
20
you will get 3 tablets (tablets of 5, 10 and 20)
*/
#include <stdio.h>
int main()
{
int num, i;
while(1) // True (non-zero is true)
{
printf("\n\nEnter a num (0 to stop): ");
scanf("%d",&num);
if (num == 0) {break;}
for(i = 1; i <= 10; i++)
{
printf("\n%d Ă %d = %d", num, i, num * i);
}
}
return 0;
}
+ 5
As Romeo Cojocaru said, the code playground is different to other environments.
I see that another user @lpang added a better way to do this as a comment to your code. Here is my attempt.
https://code.sololearn.com/coIOMWzwkQWd/?ref=app
+ 3
The corrected code!
Also, you need to understand how SoloLearn input / submit a value works. It differs from a classic IDE. Use forum search to learn more on that matter.
#1. Why did you used free() ?
#2. Why did you used a while loop with a nested for loop?
#3. What do you try to accomplish: to input 10 values or just one and print the multiplication table for that value?
#include <stdio.h>
#include <stdbool.h>
int main() {
int num, i;
//while(true){
for(i=0;i<=10;i++) {
printf("Enter a no. :\n");
scanf("%d",&num);
//for(i=1;i<=10;i++)
printf("%d Ă %d = %d\n",num,i,num*i);
//free(num);
}
return 0;
}
+ 2
I'm the updated code, change scanf to:
scanf(" %d[^\n]", &num);
this will keep \n out of the stdin buffer.
+ 1
Jeff.C
I want to take input again and again
Program should return result and ask user for input a no one more time
0
Romeo Cojocaru I want to make a program which take input from user and after giving the output it will ask for input one more time. This should continue until the user has left the program
0
Romeo Cojocaru
Eg.
Enter no :5
5Ă1=5
.
.
.
5Ă10=50
Enter no :7
7Ă1=7
.
.
.7Ă10=70
Enter no.
.
.
.
0
William Owens it's not working
0
William Owens can you please run this code on your pc after removing free()
May be because of sololearn it's not asking user for input one more time and taking previous input as the current
0
#include <stdio.h>
int main(void) {
while(1==1) {
puts("Please enter a number to multiply by 10: \n");
long long int user_number = 0;
scanf(" %lli", &user_number);
printf("%lli x 10 = %iil\n", user_number, user_number * 10);
}
}
This is a forever loop that will ask the user for a number and multiply it by 10.
Hopefully it will get you started.