Please Assist with the following 5 questions in Language C o
Please Assist with the following 5 questions in Language C only.
1). Given an int variable n that has already been declared and initialized to a positive value , and another int variable j that has already been declared , use a while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j.
2)Given int variables k and total that have already been declared , use a while loop to compute the sum of the squares of the first 50 positive integers and store this value in total. Thus your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total. Use no variables other than k and total.
3)Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared , use a while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total. Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total. Use no variables other than n, k, and total.
4)Given an integer variable timer, write a statement that uses the auto-decrement operator to decrease the value of that variable by 1.
5)Given an integer variable strawsOnCamel, write a statement that uses the auto-increment operator to increase the value of that variable by 1.
Thank you.
Solution
1)
#include <stdio.h>
int main()
{
int n=5;
int j;
while(n!=0)
{
cout<<\"*\";
n--;
}
return 0;
}
2)
#include <stdio.h>
int main()
{
int k,total=0;
printf(\"Enter the number\");
scanf(\"%d\",&k);
while(k!=0)
{
total+=k*k;
k--;
}
printf(\"Total : %d\",total);
return 0;
}
3)
#include <stdio.h>
int main()
{
int n=5;
int k,total=0;
while(n!=0)
{
total+=n*n*n;
n--;
}
printf(\"Total : %d\",total);
return 0;
}
4)
#include <stdio.h>
int main()
{
int timer;
timer--;
printf(\"Timer updated value : %d\",timer);
return 0;
}
5)
#include <stdio.h>
int main()
{
int strawsOnCamel;
strawsOnCamel++;
printf(\"strawsOnCamel updated value : %d\",strawsOnCamel);
return 0;
}

