Sum of first N

Program:

#include<stdio.h>
int main()
{
int n,sum=0,i=1;
printf("Enter number: ");
scanf("%d",&n);
while(i<=n)
{
sum=sum+i;
i++;
}
printf("Sum of first %d number: %d",n,sum);
return 0;

}

Output:



No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...