


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solutions for lab assignment #3 in the compe-160 course at san diego state university. The assignment required writing c-code to calculate the sum of digits of an integer, evaluate and print the value of a polynomial ax2 + bx + c for integer and float inputs.
Typology: Assignments
Uploaded on 09/20/2020
5 documents
1 / 4
This page cannot be seen from the preview
Don't miss anything!



I declare that all material in this assignment is my own work except where there is clear reference to the work of others. I have read, understood and agree to the SDSU Policy on Plagiarism and Cheating on the university website at http://go.sdsu.edu/student_affairs/srr/cheating-plagiarism.aspx and the syllabus for the consequences of plagiarism, including both academic and punitive sanctions.
Remark*. By submitting this assignment report electronically, you are deemed to have signed the declaration above.
Click below to enter/change your Name and RedID
1. We have to write a program that uses scanf() to input a decimal integer, calculate the sum of the digits of the written decimal integer, and, finally, use printf() to print the sum of the digits 2. C-code: #include <stdio.h> #include <stdlib.h> int main() { int n, sum = 0; printf ("Enter an integer: "); scanf ("%d", &n); printf ("\n"); while (n != 0) { sum = sum + n%10; n = n / 10; } printf ("Sum of the digits for the number entered = %d\n", sum); return 0; }
given user inputs for a, b, c, and x. But, at this time we have to use float variables.
#include <stdio.h> #include <stdlib.h> int main() { double a, b, c, x, value; printf("a b c x : "); scanf("%lf", &a); scanf("%lf", &b); scanf("%lf", &c); scanf("%lf", &x); value = a * x * x + b * x + c; printf("The value of the polynomial = %lf", value); return 0; }