Write a program that will compute the sum of the first n pos
Solution
a)))))))))))))
#include <stdio.h>
int main()
{
int j, num, sum_odd=0;
printf(\"please enter the number: \");
scanf(\"%d\", &num)
for(j=1; j<=num; j=j+2)
{
sum_odd += j;
}
printf(\"\ sum of odd numbers = %d\",sum_odd);
return 0;
}
b)))))))))))
#include <stdio.h>
int main()
{
int j=1, num, sum_odd=0;
printf(\"Enter the number: \");
scanf(\"%d\", &num);
while( j<=n)
{
sum_odd += j;
j=j+2;
}
printf(\"\ Sum_odd = %d\",sum_odd);
return 0;
}
| #include <stdio.h> int main() { int j, num, sum_odd=0; printf(\"please enter the number: \"); scanf(\"%d\", &num) for(j=1; j<=num; j=j+2) { sum_odd += j; } printf(\"\ sum of odd numbers = %d\",sum_odd); return 0; } b)))))))))))
|

