0% found this document useful (0 votes)
3 views3 pages

basics c++

The document contains multiple C++ and Java programs demonstrating basic programming concepts. These include printing 'Hello World', calculating the sum of two integers, checking if a number is even or odd, determining if a year is a leap year, and checking if a number is positive or negative. Additionally, it includes a Java program to check if a number is divisible by 5.

Uploaded by

sridhar2879
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

basics c++

The document contains multiple C++ and Java programs demonstrating basic programming concepts. These include printing 'Hello World', calculating the sum of two integers, checking if a number is even or odd, determining if a year is a leap year, and checking if a number is positive or negative. Additionally, it includes a Java program to check if a number is divisible by 5.

Uploaded by

sridhar2879
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// Your First C++ Program

#include <iostream>

int main() {
std::cout << "Hello World!";
return 0;
}

#include <iostream>

using namespace std;

int main() {

int x, y;

int sum;

cout << "Type a number: ";

cin >> x;

cout << "Type another number: ";

cin >> y;

sum = x + y;

cout << "Sum is: " << sum;

return 0;

/*

* C++ program to check if given integer is even or odd

*/

#include<iostream>

using namespace std;

int main()

int number, remainder;

cout << "Enter the number : ";

cin >> number;


remainder = number % 2;

if (remainder == 0)

cout << number << " is an even integer " << endl;

else

cout << number << " is an odd integer " << endl;

return 0;

/*

* C++ Program to Check if the Entered Year is a Leap Year

*/

#include <iostream>

using namespace std;

int main()

int year;

cout << "Enter the year in yyyy format : ";

cin >> year;

if (year % 4 == 0)

cout << year << " is a leap year";

else

cout << year << " is not a leap year";

#include <stdio.h>

void main()

int number;
printf("Enter a number \n");

scanf("%d", &number);

if (number >= 0)

printf("%d is a positive number \n", number);

else

printf("%d is a negative number \n", number);

import java.util.Scanner;

public class Check_Divisiblity

public static void main(String[] args)

int n;

Scanner s = new Scanner(System.in);

System.out.print("Enter any number:");

n = s.nextInt();

if(n % 5 == 0)

System.out.println(n+" is divisible by 5");

else

System.out.println(n+" is not divisible by 5");

You might also like