In: Computer Science
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer.
Code so far:
char sentence[50];
int count = 0;
int c;
printf("\nEnter a sentence: ");
fgets(sentence, 50, stdin);
sscanf(sentence, %s;
for(c=0; sentence[c]; c++){
count++;
}
int num;
printf("\nEnter a number: ");// enter a number for generating the
pyramid
sscanf("%d",&num);
int product = num*count;
printf("\n%d",product);

#include <stdio.h>
int main(void) {
char sentence[50];
int count = 0;
int c;
printf("\nEnter a sentence: ");
fgets(sentence, 50, stdin);
// fgets puts a new line character at the last
for(c=0; sentence[c] != '\n'; c++){
count++;
}
int num;
printf("\nEnter a number: "); // enter a number for generating the pyramid
scanf("%d",&num);
int product = num*count;
printf("\n%d",product);
return 0;
}
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.