Draw a flow chart of a program that adds N odd numbers starting from 1. The value of N should be input by the user .
I have the flowchart, could any one please write the algorithm for it?
attached it.
Attachments:
Answers
Answered by
2
#include
void main()
{
int NUM,i,SUM=0;
clrscr();
printf(“\nENTER INTERGER NUMBER : “);
scanf(“%d”,&NUM);
for(i=1;i
Answered by
1
A program that adds N odd numbers starting from 1. The value of N should be input by the user.
SOURCE CODE:
#include<iostream>
using namespace std;
int main()
{
int N;
int sum = 0;
cout<<"Enter the odd numbers:"<endl;
cin>>N;
for(int i =1 ; i<N*2; i++)
{
if(i%2 !=0)
{
sum = sum+i;
}
}
cout<<"Sum:"<<sum<<endl;
return 0;
}
ALGORITHM:
- Take the number N as the upper limit.
- Initialize sum as 0.
- For i ranging from 1 to N.
- If i is odd, then.
- sum := sum + i.
- End if.
- Display the sum
#SPJ3
Similar questions
Math,
7 months ago
Hindi,
7 months ago
Psychology,
7 months ago
English,
1 year ago
Environmental Sciences,
1 year ago