To generate the series 1+3+5+7+... using C program
Answers were Sorted based on User's Feedback
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 ? | 263 Yes | 164 No |
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 ? | 72 Yes | 37 No |
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 ? | 46 Yes | 24 No |
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 ? | 26 Yes | 11 No |
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 ? | 36 Yes | 22 No |
#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 ? | 35 Yes | 21 No |
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 ? | 38 Yes | 26 No |
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 ? | 16 Yes | 7 No |
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 ? | 20 Yes | 14 No |
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 ? | 8 Yes | 4 No |
char* f() return "hello:"; void main() {char *str=f(); }
class test { int a; public: test(int b):a(b){} void show(){ cout<<a; } }; void main() { test t1; test t2(5); t1.show(); t2.show(); } }
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;
void main() { int i=5; printf("%d",i+++++i); }
who was the present cheif governor of reserve bank of india
6 Answers State Bank Of India SBI,
How to convert hexadecimal to binary using c language..
1 Answers Bajaj, GAIL, Satyam, Zenqa,
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
Display this kind of output on screen. 1 0 1 1 0 1 3. Display this kind of output on screen. 1 1 0 1 0 1 4. Display this kind of output on screen. 1 1 0 1 0 1 5.Display this kind of output on screen. 1 2 3 4 5 6 7 8 9 10
how to convert decimal to hexadecimal without using arrays just loops
what is exceptions?
Given that two int variables, total and amount , have been declared, write a sequence of statements that: initializes total to 0 reads three values into amount , one at a time. After each value is read in to amount , it is added to the value in total (that is, total is incremented by the value in amount ). Instructor's notes: If you use a loop, it must be a for loop. And if you use a loop control variable for counting, you must declare it.
write the value of x and y after execution of the statements: int x=19,y; y=x++ + ++x; x++; y++;