Showing posts with label Basic Programs. Show all posts
Showing posts with label Basic Programs. Show all posts
Friday, October 18, 2013
Java Program to test whether a given year is a leap year or not
Code:-
import java.util.Scanner;class Leap{
public static void main(String args[]){
System.out.println("Enter year");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
if((a%100)==0){
if((a%400)==0)
System.out.println(a+" is a century year and a leap year too");
else
System.out.println(a+" is a century year");
}
else{
if((a%4)==0)
System.out.println(a+" is leap year ");
else
System.out.println(a+" is not a leap year");
}
}
}
Output:-

Monday, October 14, 2013
Java Program to read text using readline function
import java.io.*;
class Read{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter text \n stop to terminate" );
do{
str= br.readLine();
System.out.println(str);
}
while(str.equals("Stop"));
}
}
class Read{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter text \n stop to terminate" );
do{
str= br.readLine();
System.out.println(str);
}
while(str.equals("Stop"));
}
}
Friday, September 27, 2013
C++ Program using nested if else
Saturday, September 21, 2013
Java program to create a frame using Swing
Tuesday, September 17, 2013
C++ Program to multiply two matrices with Output
Program
#include<iostream>
using namespace std;
int main(){
int i,j,a[3][3],b[3][3],c[3][3];
cout<<"Enter first matrix";
for(i=0;i<3;i++){
for(j=0;j<3;j++){
cin>>a[i][j];
}
cout<<endl;
}
cout<<"Enter second matrix";
for(i=0;i<3;i++){
for(j=0;j<3;j++){
cin>>b[i][j];
}
cout<<endl;
}
for(i=0;i<3;i++){
for(j=0;j<3;j++){
c[i][j]=a[i][j]*b[i][j];
}
}
for(i=0;i<3;i++){
for(j=0;j<3;j++){
cout<<c[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
Output:-
Saturday, September 7, 2013
C++ Program to find the average of given numbers with output
#include<iostream>
using namespace std;
int main(){
int n,i,a[50];
float average,total=0;
cout<<"Enter the total number of elements(max 50)";
cin>>n;
for(i=0;i<n;i++){
cout<<"Enter the "<<i+1<<" number:";
cin>>a[i];
}
for(i=0;i<n;i++){
total=a[i]+total;
}
average=total/n;
cout<<"The sum of the given numbers is "<<total<<endl;
cout<<"The average is "<<average;
return 0;
}
using namespace std;
int main(){
int n,i,a[50];
float average,total=0;
cout<<"Enter the total number of elements(max 50)";
cin>>n;
for(i=0;i<n;i++){
cout<<"Enter the "<<i+1<<" number:";
cin>>a[i];
}
for(i=0;i<n;i++){
total=a[i]+total;
}
average=total/n;
cout<<"The sum of the given numbers is "<<total<<endl;
cout<<"The average is "<<average;
return 0;
}
Output:-
Thursday, August 29, 2013
C++ Program to print floyd triangle
Wednesday, August 28, 2013
C++ Program to find the multiplication table of any number
Tuesday, August 27, 2013
C++ Program to print triangle of stars
Downward triangle:-
#include<iostream>using namespace std;
int main(){
int i,j;
for(i=5;i>0;i--){
for(j=1;j<=i;j++){
cout<<"*";
}
cout<<endl;
}
return 0;
}
output:-
Download the source code file (.cpp file) from dropbox
Upward triangle:-
#include<iostream>
using namespace std;
int main(){
int i,j;
for(i=1;i<6;i++){
for(j=1;j<=i;j++){
cout<<"*";
}
cout<<endl;
}
return 0;
}
using namespace std;
int main(){
int i,j;
for(i=1;i<6;i++){
for(j=1;j<=i;j++){
cout<<"*";
}
cout<<endl;
}
return 0;
}
Output:-
Subscribe to:
Posts (Atom)






