google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a program to find the sum of first n odd numbers - 2nd puc computer science

Write a program to find the sum of first n odd numbers

Write a program to find the sum of first n odd numbers

#include<stdio.h>

#include<conio.h>

void main()

{

int n,i=1,sum=0;

clrscr();

printf("Enter the number: ");

scanf("%d",&n);

do

{

sum=sum+i;

i=i+2;

}while(i<=n);

printf("Sum=%d",sum);

getch();

}

Output:

Enter the number: 10

Sum=25

Write a program to find the sum of first n odd numbers Write a program to find the sum of first n odd numbers Reviewed by Vision Academy on December 08, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.