Auto Draft
Coding Question 12
Question : 12
Instructions: You are required to write the code. You can click on compile and run anytime to check compilation/execution status. The code should be logically/syntactically correct.
Problem: Write a program in C to display the table of a number and print the sum of all the multiples in it.
Test Cases:
Test Case 1:
Input:
5
Expected Result Value:
5, 10, 15, 20, 25, 30, 35, 40, 45, 50
275
Test Case 2:
Input:
12
Expected Result Value:
12, 24, 36, 48, 60, 72, 84, 96, 108, 120
660
C
C++
Java
Python
C
#include <stdio.h>
int main()
{
int n, i, value=0, sum=0;
printf("Enter the number for which you want to know the table: ",n);
scanf("%d",&n);
for(i=1; i<=10; ++i)
{
value = n * i;
printf("table is %d \n",value);
sum=sum+value;
}
printf("sum is %d",sum);
return 0;
}
C++
#include <iostream>
using namespace std;
int main()
{
int n, i, value=0, sum=0;
cout<<"Enter the number for which you want to know the table: ",n;
cin>>n;
for(i=1; i<=10; ++i)
{
value = n * i;
cout<<value<<endl;
sum=sum+value;
}
cout<<"sum is "<<sum ;
return 0;
}
Java
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Any No:");
int no = sc.nextInt();
int sum=0,value=1;
for(int i=1 ; i<=10 ; i++) {
value = no*i;
System.out.println(value);
sum=sum+value;
}
System.out.println("Sum is : "+sum);
}
}
Python
table_number = int(input())
sum = 0
for i in range(1, 11):
value = table_number * i
print(value, end=" ")
sum = sum + value
print()
print(sum)