Friday, December 30, 2016

Series

Write a program print series.
1. 1 3 6 10 15
2. 2 4 7 11  16



void main()
{
int i,j=1;//same java,c,c++
for(int i=1;i<=5;i++)
{
j=j+i;
printf("%d",j);//c program
System.out.println(j);//java
cout<<j;//c++
}


}
2.
void main()
{
int i,j=0;//same java,c,c++
for(int i=1;i<=5;i++)
{
j=j+i;
printf("%d",j);//c program
System.out.println(j);//java
cout<<j;//c++
}


}

No comments:

Post a Comment