Monday, May 24, 2010

(a) Create a new C Program file called Lab3d.c(b) Write a program to input 10 numbers and calculate the sum.?

#include%26lt;stdio.h%26gt;


#define size 10


int main()


{


int nums[size],i,sum=0;


printf("Enter the numbers\n");


for(i=0;i%26lt;size;i++)


{


scanf("%d",%26amp;nums[i]);


}


for(i=0;i%26lt;size;i++)


{


sum+=nums[i];


}


printf("sum=%d\n",sum);


return 0;


}


//create a new c program file called lab3d.c......... sum.? ... copy and paste the code and save it as lab3d.c file then compile it using any of the c or c++ compilers

(a) Create a new C Program file called Lab3d.c(b) Write a program to input 10 numbers and calculate the sum.?
#include %26lt;stdio.h%26gt;


main()


{


int i, num, sum;


i=0;


sum=0;


while (i++%26lt;10)


{


scanf("%d", %26amp;num);


sum=sum+num;


}


printf("sum = %d\n", sum);


}


No comments:

Post a Comment