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 ?    263 Yes 163 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 ?    72 Yes 37 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 ?    46 Yes 24 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 ?    26 Yes 11 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 ?    36 Yes 22 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 ?    35 Yes 21 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 ?    38 Yes 26 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 ?    16 Yes 7 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 ?    20 Yes 14 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 ?    8 Yes 4 No

Post New Answer

More C C++ Errors Interview Questions

what is meant for variable not found?

3 Answers  


wap for bubble sort

3 Answers  


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

1 Answers  


I am using Qt 5.6 during compilation it stops and gives error about Qmake The process "C:QtQt5.6.35.6.3msvc2015_64inqmake.exe" crashed. Error while building/deploying project untitled1 (kit: Desktop Qt 5.6.3 MSVC2015 64bit) When executing step "qmake"

0 Answers  


UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls....

5 Answers  






write a profram for selection sort whats the error in it?

2 Answers  


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

1 Answers  


write the value of x and y after execution of the statements: int x=19,y; y=x++ + ++x; x++; y++;

0 Answers  


#include<iostream.h> #include<stdlib.h> static int n=0; class account { int age,accno; float amt; char name[20]; public: friend void accinfo(account [] ,int); void create(); void balenq(); void deposite(); void withdrawal(); void transaction(account []); }; void account :: create() { static int acc=1231; accno=acc+n; cout<<"\n\tENTER THE CUSTOMER NAME : "; cin>>name; cout<<"\n\t ENTER THE AGE : "; cin>>age; cout<<"\n\t ENTER THE AMOUNT : "; cin>>amt; // if(amt<=500) // cout<<"\n\tAMOUNT IS NOT SUFFICIENT TO CREATE AN ACCOUNT..."; cout<<"\n\t YOUR ACCOUNT NUMBER : "<<accno<<endl; n++; } void accinfo(account cus[],int ch) { int no,flag=0; cout<<"\n\t\tENTER YOUR ACCOUNT NUMBER : "; cin>>no; for(int i=0;i<=n&&flag==0;i++) if(no==cus[i].accno) { flag=1; switch(ch) { case 2: cus[i].balenq(); break; case 3: cus[i].deposite(); break; case 4: cus[i].withdrawal(); break; case 5: cus[i].transaction(cus); break; default: cout<<"\n\t\tEND OF THE OPERATION"; exit(1); } } if(flag==0) cout<<"\n\t\tYOUR ACCOUNT DOES NOT EXIST..."<<endl; } void account :: balenq() { cout<<"\n\t\tCUSTOMER NAME : "<< name << endl; cout<<"\n\t\tBALANCE : "<< amt << endl; } void account :: deposite() { int damt; cout<<"\n\t\tCUSTOMER NAME : "<< name <<endl; cout<<"\n\t\tBALANCE : "<< amt <<endl; cout<<"\n\tENTER THE AMOUNT TO BE DEPOSITED : "; cin>>damt; amt+=damt; cout<<"\n\t\tYOUR CURRENT BALANCE : "<<amt<<endl; } void account :: withdrawal() { int wamt; cout<<"\n\t\tCUSTOMER NAME : "<< name; cout<<"\n\t\tBALANCE : "<< amt; cout<<"\n\tENTER THE AMOUNT TO BE WITHDRAWN : "; cin>>wamt; if(amt-wamt>=500) { amt-=wamt; cout<<"\n\t\tYOUR CURRENT BALANCE : "<<amt; } else cout<<"\n\tYOUR BALANCE IS TOO LOW FOR WITHDRAWAL..."<<endl; } void account :: transaction (account cus[]) { int no,tamt,flag=0; cout<<"\n\tENTER THE RECEIVER'S ACCOUNT NUMBER : "; cin>>no; cout<<"\n\t\t ENTER THE AMOUNT : "; cin>>tamt; for(int i=0;i<=n&&flag==0;i++) if(cus[i].accno==no) { flag=1; cus[i].amt+=tamt; amt-=tamt; cout<<"\n\t\tYOUR CURRENT BALANCE : "<<amt<<endl; cout<<"\n\t\t RECEIVER'S BALANCE : "<<cus[i].amt<<endl; } if(flag==0) cout<<"\n\tRECEIVER'S ACCOUNT NUMBER IS NOT AVALIABLE..."<<endl; } void main() { account cus[10]; int ch; do { cout<<"\n\t\t BANK ACCOUNT"; cout<<"\n\t\t ************\n"; cout<<"\n\t\t1.CREATE AN ACCOUNT"; cout<<"\n\t\t2.BALANCE ENQUIRY"; cout<<"\n\t\t3.DEPOSITE"; cout<<"\n\t\t4.WITHDRAWAL"; cout<<"\n\t\t5.TRANSACTION"; cout<<"\n\t\t6.EXIT\n\n"; cout<<"\n\t\tENTER YOUR CHOICE : "; cin>>ch; if(ch==1) cus[n].create(); else accinfo(cus,ch); }while(1); }

1 Answers  


quoroum of computer languages?

0 Answers   Infosys,


errors are known as?

3 Answers   EX, State Bank Of India SBI,


Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .

2 Answers  


Categories