#A program that finds the sum of all odd numbers between M to N.
// in Notepade wirte m=10 and n=100 then save as file5.txt//
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- long long int i,m,n,sum;
- clrscr();
- FILE *p;
- p=fopen("file5.txt","r");
- fscanf(p,"%lld %lld",&m,&n);
- for(i=m;i<=n;i++){
- if(i%2==1)
- printf(" %lld ",i);}
- sum=0;
- for(i=m;i<=n;i++){
- if(i%2==1)
- sum=sum+i;}
- printf("\n\nSum of ODD numbers=%lld\n",sum);
- getch();
- }
// in Notepade wirte m=10 and n=100 then save as file5.txt//
RULES & output:
1.Program type:used by for loop and if.
2.Simple input:10-100
3.Simple output:11 13 15 17 19 21 23 ………………99.
Sum=2475.
1.Program type:used by for loop and if.
2.Simple input:10-100
3.Simple output:11 13 15 17 19 21 23 ………………99.
Sum=2475.
No comments:
Post a Comment