To generate the series 1+3+5+7+... using C program




Answers were Sorted based on User's Feedback



To generate the series 1+3+5+7+... using C program..

Answer / s.vyasaraj

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=1,sum=0;
clrscr();
printf("enter the value for n:");
scanf("%d",&n);
while(i<=n)
{
sum=sum+i;
i=i+2;
}
printf("the series is =%d");
getch()
}

Is This Answer Correct ?    205 Yes 134 No

To generate the series 1+3+5+7+... using C program..

Answer / chue kimcheang

C++
void main()
{
int i,n,sum=0;
cout<<"N=";
cin>>n;
for(i=1;i<=n;i=i+2)
sum=sum+i;
cout<<"\n1+3+5+7+....+"<<n<<"="<<sum;
}

C program....
void main()
{
int i,n,sum=0;
printf("N=");
scanf("%d",&n);
for(i=1;i<=n;i=i+2)
sum=sum+i;
printf("\n1+3+5+7+....+%d=%d",n,sum);
}

Is This Answer Correct ?    57 Yes 30 No

To generate the series 1+3+5+7+... using C program..

Answer / naresh kumar

In the answer Printf function is worng here the value for %
d is not mentioned it would like

printf("the series is =%d", sum);

Is This Answer Correct ?    34 Yes 18 No




To generate the series 1+3+5+7+... using C program..

Answer / mariaalex007

#include"stdio.h"
#include"conio.h"
void main()
{
int s=0;
for(int i=1;i<100;i++)
{
if(i%2==0)
continue;
s=s+i;
}
printf("The answer is...%d",s);
getch();
}

Is This Answer Correct ?    29 Yes 15 No

To generate the series 1+3+5+7+... using C program..

Answer / @pravin.08

main()
{
int i=1,n;
printf("enter n ");
scanf("%d",&n);
while(i<=n)
{
printf("%d+",i);
i+=2;
}
}

Is This Answer Correct ?    35 Yes 22 No

To generate the series 1+3+5+7+... using C program..

Answer / mazharul haque

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,s=0;
printf("ENTER A RANGE ");
scanf("%d",& n);
printf("1");
for(i=3; i<=n; i=i+2)
{
s=s+i;
printf("+%d",i);
}
printf("=%d",s+1);
getch();
}

Is This Answer Correct ?    21 Yes 9 No

To generate the series 1+3+5+7+... using C program..

Answer / mazharul haque

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,s=0;
printf("ENTER A RANGE ");
scanf("%d",n);
for(i=1; i<=n; i=i+2)
{
s=s+i;
printf("%d+",i);
}
printf("=%d",s);
getch();
}

Is This Answer Correct ?    32 Yes 21 No

To generate the series 1+3+5+7+... using C program..

Answer / gaurav pitaliya

#include<stdio.h>
#include<conio.h>
void main()
{
int i,s=0;
clrscr();
for(i=0; i<=10; i++)
{
s=s+(2*i)+1;
}
printf("The Sum of series is= %d",s);
getch();
}

Is This Answer Correct ?    18 Yes 9 No

To generate the series 1+3+5+7+... using C program..

Answer / nagarajan

Simplest method to do it ..

for(int a=0;a<10;a++){
(a&1)?printf("%d\n",a):printf("\n");
}

Is This Answer Correct ?    13 Yes 7 No

To generate the series 1+3+5+7+... using C program..

Answer / aoyn

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i,n,sum=0;
cout<<“1+2+3+……+n”;
cout<<“nEnter the value of n:”;
cin>>n;

for(i=1;i<=n;++i)
sum+=i;
cout<<“nSum=”<<sum;
getch();
}

Is This Answer Correct ?    7 Yes 3 No

Post New Answer



More C C++ Errors Interview Questions

what is syntax error?

3 Answers  


Write a program to accept two strings of Odd lengths. Then take all odd characters from one string and even characters from the other and concatenate and produce a string.

1 Answers  


What is the code for following o/p * * * * * * * * * * * * * * * *

1 Answers  


char* f() return "hello:"; void main() {char *str=f(); }

1 Answers  


How to upgrade LOOP environment, I just mean, how can i make loop statement editable ? I just try some program using loop statement and checking it in multiple compilers. Every compiler showing different output, what's the wrong ? is it a compiler based problem, or loop based problem, tell me why ? and what will be the debugging process, for this kind of problem ?

1 Answers  






what is exceptions?

5 Answers   Wipro, HCL,


how to convert decimal to binary in c using while loop without using array

50 Answers   Aptech, Apple, C2D Software, Arwen Tech, CEC, BCS,


To generate the series 1+3+5+7+... using C program

18 Answers  


What is the out put of this programme? int a,b,c,d; printf("Enter Number!\n"); scanf("%d",&a); while(a=!0) { printf("Enter numbers/n"); scanf("%d%d%d",&b,&c,&d); a=a*b*c*d; } printf("thanks!"); getche(); Entering numbers are a=1,b=2,c=3,d=4 b=3,c=4,d=-5 b=3,c=4,d=0

5 Answers   TCS,


void main() { int i=1; printf("%d%d%d",i,++i,i++); } Cau u say the output....?

23 Answers   HCL,


when i use cout or cin call & then either << or >> .....it shows declaration syntax error...what should i do? cout<<"anything"; int a; cin>>a; return 0;

2 Answers  


full c programming error question based problem

3 Answers   TCS, HCL,






Categories