Category Archives: Pratice Problem

Java program to check whether it is a multiple of 7 or not

Given an integer n, check whether it is a multiple of 7 or not. If the number is divisible by 7, then return true else return false.

Constraints

1 <= n <= 1000

Sample TestCase
Input
27
Output
0
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class MultipleOfSeven {
 public static boolean sevenBySeven(int num){
    if(num%7==0){
        return true;
     }else{
       return false;
 }
 public static void main(String[] args) throws IOException{
 Scanner in = new Scanner(System.in);
 boolean output;
 int ip1 = Integer.parseInt(in.nextLine().trim());
 output = sevenBySeven(ip1);
 System.out.println(String.valueOf(output ? 1 : 0));
 }
}

Java program for a given number n, finds a number p which is greater than or equal to n and is a power of 2.

Java Program for Replacing White Space Characters

Learn Android Programming – For Beginners To Pro

Advertisements

C program to shift inputed data by two bits to the left

This C program shift inputed data by two bits to the left


// C program to shift inputed data by two bits to the left
//Author: Sani Kamal
//Date:04-06-2015

int main(){
int num,temp;
printf("Enter any integer:");
scanf("%d",&num);
num<<=2;
temp=num;
printf("\nThe left shifted data is:%d",temp);
return 0;
}

/*
INPUT:
Enter any integer:5
OUTPUT:
The left shifted data is:20

*/

INPUT:
Enter any integer:2
OUTPUT:
The left shifted data is:8

Life, the Universe, and Everything

C program to find entered year is leap year or not

ScreenShots:

Untitled

C Program to find whether given number is even or odd

This c program check whether number is even or odd and print the result to the console.


// C program to find whether given number is even or odd

//Author:Sani kamal
//date: 24-08-2017

#include<stdio.h>

int main(){
int num;
printf("Enter any integer:\n");
scanf("%d",&num);
if(num%2==0)
printf("number is even");
else
printf("number is odd");

&nbsp;

return 0;

}
/*

INPUT:
Enter any integer:10
OUTPUT:
number is even

*/

INPUT:
Enter any integer:13
OUTPUT:
number is odd

C Language Decision Statements

C Program to find sum of two number

 

Screen shots:Untitled.png

C program to find entered year is leap year or not

This C program to find entered year is leap year or not. This program use if else condition.


// C program to find entered year is leap year or not
//Author:Sani kamal
//date: 24-08-2017

#include<stdio.h>

int main(){
int yr;
printf("Enter any year:\n");
scanf("%d",&yr);
if(yr%4==0)
printf("year is leap year");
else
printf("year is not leap year");

&nbsp;

return 0;

}
/*
Output:
Enter any year:1947
year is not leap year

*/

Output:
Enter any year:2012
year is leap year

 

Introduction to Java

HTML Elements   Java variables

Java program to swap first name and last name

C program to show the use of conditional operator

C program to show the use of conditional operator

This C program show the use of conditional operator. This program find greatest among two number


// C program to show the use of conditional operator
//This C program find greatest among two numbers
//Author:Sani kamal
//date: 24-08-2017

#include<stdio.h>

int main(){
int num1,num2;
printf("Enter the value for num1 and num2:\n");
scanf("%d%d",&num1,&num2);
(num1>num2) ? printf("num1 is greatest"): printf("num2 is greatest");

&nbsp;

return 0;

}
/*
Output:
Enter the value for num1 and num2:
12
34

num2 is greatest

*/

 

Output:
Enter the value for num1 and num2:
2
4

num2 is greatest

 

 

C program to find greatest of three number

C program to reverse a given numberC program to show swap of two number without using third variables

C program to find greatest of three number

This C program find greatest of three number using if conditional statement.


// C program to find greatest in three numbers
//Author:Sani kamal
//date: 24-08-2017

#include<stdio.h>

int main(){
int x,y,z;
printf("Enter the value for x,y& z:\n");
scanf("%d%d%d",&x,&y,&z);
if ((x>y)&&(x>z))
printf("x is greatest");
if((y>z)&&(y>x))
printf("y is greatest");
if ((z>x)&&(z>y))
printf("z is greatest");

&nbsp;

return 0;

}
/*
Output:
Enter the value for x,y & z:
12
34
56
z is greatest

*/

C program to reverse a given number

C program to calculate sum of 5 subjects and find percentage

C program to reverse a given number

This c program reverse a number given by user.


// C program to reverse a given number
//Author:Sani kamal
//date: 24-08-2017

#include<stdio.h>

int main(){
int num,a ,rev=0;
printf("Enter any integer:\n");
scanf("%d",&num);
while(num>=1){
a=num%10;
rev=rev*10+a;
num=num/10;

}
printf("Reverse:%d",rev);

&nbsp;

return 0;

}

Oputput:

Enter any integers:123

Reverse:321

 

C program to show swap of two number without using third variables

Algorithm paradigms (Introduction)

C program to show swap of two number without using third variables

This c program show swap of two number without using third variables.


// C program to show swap of two number without using third variables
//Author:Sani kamal
//date: 24-08-2017

#include<stdio.h>

int main(){
int num1,num2;
printf("Enter the value for num1 and num2:\n");
scanf("%d%d",&num1,&num2);
num1=num1+num2;
num2=num1-num2;
num1=num1-num2;
printf("After swapping the value of num1 and num2:%d %d",num1,num2);

&nbsp;

return 0;

}

Output:

Enter the value for num1 and num2:

3

5

After swapping the value of num1 and num2 :5  3

 

 

 

C program to calculate sum of 5 subjects and find percentage

C program to convert temperature degree centigrade to fahrenheit

C program to calculate sum of 5 subjects and find percentage

This C program calculate sum of five subjects and find percentage


// C program to calculate sum of five subject and find percentage
//Author:Sani kamal
//date: 24-08-2017

#include<stdio.h>

int main(){
int s1,s2,s3,s4,s5,sum, total=500;
float per;
printf("Enter marks of five subject:");
scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);
sum=s1+s2+s3+s4+s5;
printf("Total marks::%d",sum);
per=sum*100/total;
printf("Average marks:%f",per);

return 0;

}

Oputput:

Enter marks of five subjects:

50

70

65

75

85

Total mark:345

Average mark:69.0000

 

C program to find simple interest

C program to find area and circumference of a circle

Overview of C language

C program to find simple interest

This c program calculate simple interest from given principle amount, rate of interest and time .


// C program to calculate simple interest
//Author:Sani kamal
//date: 24-08-2017

#include<stdio.h>

int main(){
int p, r,t,si;
printf("Enter principle,rate of interest and time to calculate simple interest:");
scanf("%d%d%d",&p,&r,&t);
si=(p*r*t)/100;
printf("Simple interest:%d",si);

return 0;

}

Output:

Enter principle ,rate of interest and time to calculate simple interest:

500

5

10

Simple interest:250

 

C program to find area and circumference of a circle