Programmes
Programmes
\n"); // return 0; }
2.ADDING 2 NUMBERS
/* add2.c -- Add two numbers and print them out together with their sum AUTHOR: DATE: */ #include <stdio.h> int main(void) { int first, second; printf("Enter two integers > "); scanf("%d %d", &first, &second); printf("The two numbers are: %d %d\n", first, second); printf("Their sum is %d\n", first+second);
printf("Enter a positive number n > "); scanf("%d",&n); /* We should check that n is really positive*/ sum = 0; for (lcv=0; lcv < n; lcv++) { printf("\nEnter an integer > "); scanf("%d",¤t); /* printf("\nThe number was %d\n", current); */ sum = sum + current; } printf("The sum is %d\n", sum); return 0;