Answer:
#include <stdio.h>
#include <string.h>
int main(){
char number[100];
printf("Number: ");
scanf("%s", number);
int sum = 0;
for(int i =0;i<strlen(number);i++){
sum+= number[i] - '0';
}
printf("Sum: %d",sum);
return 0;
}
Explanation:
This declares a c string of 100 characters
char number[100];
This prompts user for input
printf("Number: ");
This gets user input
scanf("%s", number);
This initializes sum to 0
int sum = 0;
This iterates through the input string
for(int i =0;i<strlen(number);i++){
This adds individual digits
sum+= number[i] - '0';
}
This prints the calculated sum
printf("Sum: %d",sum);
return 0;
Answer:
The name of a .java file should <u>always match the name of the class inside.</u>
Explanation:
In Java programming the program written in code editor is first saved with .java extension. The name of this .java file should be same as that of the class declared inside the file.
This .java file is then compiled and converted to .class file which contains the java bytecode. This bytecode can then be executed by java virtual machine(JVM).
However it is not always necessary that name of .java files should be same as that of class inside it. The name should be same only when the class inside is declared as public.
In case it is not declared as public one can name .java file different than the actual class name.
The function use to get the number of element in a dictionary is len.
<h3>What is a dictionary?</h3>
Dictionaries are used to store data values in key-value pairs. Dictionary are ordered.
Dictionary in python are express as follows:
my_dict = {"name": "Michael", "age": 28, "school": "Oxford"}
Therefore, the length of the element of the dictionary can be gotten using the len() function.
Hence,
print(len(my_dict)) will give you the length of the element.
learn more on dictionary here: brainly.com/question/14120893
#SPJ11
Answer:
import random
a = random.randint(1,10)
b = random.randint(1,10)
answer = a * b
print (str(a) + " X " + str(b) + " = " + str(answer))
Explanation:
Happy to help you mate