PPS Practical 42
- Aim: Write a program that defines a function to add first n numbers.
- Code:
//For turbo C++ remove below comments #include <stdio.h> //#include<conio.h> int addupton(int n){ int sum=0; for (int i = 1; i <=n; i++){ sum+=i; } return sum; } void main() { int n; //clrscr(); printf("For 1+2+3+4+...+n"); printf("\nEnter value of n : "); scanf("%d",&n); printf("sum of firsst n number : %d",addupton(n)); // getch(); }
- Output:
Comments
Post a Comment