Sum of n numbers -
#include <stdio.h>
int main()
{ int n,i,s=0;
printf("Enter the number ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{ s=s+i;
}
printf("The sum is %d",s);
return 0;
}
Output -
Enter the number 5
The sum is 15
#include <stdio.h>
int main()
{ int n,i,s=0;
printf("Enter the number ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{ s=s+i;
}
printf("The sum is %d",s);
return 0;
}
Enter the number 5
The sum is 15
0 Comments