NPTEL (14 Sep - 04 Dec ) | Week 1 : Program 3and Program 4 Programming in JAVA Solutions2020.

 





        Programming in JAVA.       




Java Week 1: Q3

Consider first n even numbers starting from zero(0).Complete the code segment to calculate sum of  all these numbers divisible by 3 . Print the sum.

Example:

Input: n = 5

-------
0 2 4 6 8
Even number divisible by 3:0 6
sum:6

PROGRAM:

int i=0,a=0;
while(a<n)
{ 


  if(i%2==0)
  {
     if(i%3==0)
     { 
        sum=sum+i;
     } 
       a=a+1;
  }
  i++;
}

System.out.print(sum);

Java Week 1: Q4

Complete the code segment to check whether the number is an Armstrong number or not.

PROGRAM:

int a=n,c=0,b;

while(n>0)
{
  b=n%10;
  n=n/10;
  c=c+(b*b*b);
  
  
}

if(a==c)
  System.out.print("1");
else
   System.out.print("0");
FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100%  correct solutions.

No comments:

Post a Comment

If you have any problems related to solutions or any concept please let me know.

Copyright (c) 2020 Custom Programs All Right Reserved

Pages