Write a program to display the following format:
Logic:
First column contains natural numbers serially..
second column contains ( Current first column element+ previous second column element)
2+1=3
3+3=6
4+6=10
5+10=15
#include<stdio.h>
main()
{
int j=0,z,i,n;
printf("Enter the Limit... : ");
scanf("%d",&n);
printf("\n----------------\n
printf("no\tsum");
printf("\n------------------\n");
for(i=1;i<=n;i++)
{
printf("\n%d",i);
j+=i;
printf("\t%d",j);
} getch();
}
No | sum |
1 | 1 |
2 | 3 |
3 | 6 |
4 | 10 |
5 | 15 |
Logic:
First column contains natural numbers serially..
second column contains ( Current first column element+ previous second column element)
2+1=3
3+3=6
4+6=10
5+10=15
#include<stdio.h>
main()
{
int j=0,z,i,n;
printf("Enter the Limit... : ");
scanf("%d",&n);
printf("\n----------------\n
printf("no\tsum");
printf("\n------------------\n");
for(i=1;i<=n;i++)
{
printf("\n%d",i);
j+=i;
printf("\t%d",j);
} getch();
}
0 comments :
Post a Comment