In: Computer Science
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=1,j=11,temp;
float avg,float_sum;
int sum,input;
//First Ten Natural Numbers
printf("First Ten Natural Numbers:\n");
while(i<=10)
{
printf("%d\t",i);
i++;
}
while(j<=20)
{
sum+=j;
j++;
}
//Sum of second set of 10 Natural Numbers
printf("\nSum of second set of 10 Natural Numbers: %d",sum);
i=1,sum=0;
printf("\nEnter a number: ");
scanf("%d",&input);
while(i<=input)
{
printf("%d\n",i);
sum+=i;
i++;
}
//Sum of Natural Numbers up to given number (The sum is calculated in the above for loop and printed in following line)
printf("Sum of Natural Numbers up to %d is: %d\n",input,sum);
i=0;
//PRINTING CUBES UPTO GIVEN NUMBER
printf("\n-----Cubes-----\n");
while(i<=input)
{
printf("\nCube of %d is : %d\n",i,i*i*i);
i++;
}
j=0;
//MULTIPLICATION TABLE USING WHILE LOOP
printf("\n-----Multiplication Table-----\n");
while(j<=10)
{
printf("\n%d x j = %d",input,input*j);
j++;
}
i=1;
printf("\n");
printf("\n");
//PRINTING GIVEN NUMBER OF ASTERISKS SEPERATED BY TAB
while(i<=input)
{
printf("*\t");
i++;
}
printf("\n");
sum=0,i=1;
//PROMPTING USER FOR 10 INTEGERS
printf("\nEnter 10 integers: \n");
while(i<=10)
{
scanf("%d",&temp);
sum+=temp;
i++;
}
//PRINTING SUM OF INTEGERS
printf("\nSum of 10 integers Entered: %d\n",sum);
float_sum = sum;
avg = float_sum/10;
//PRINTING AVERAGE OF INTEGERS
printf("\n Average of 10 integers Entered: %.4f\n",avg);
return 0;
}
Code has comment on each section.The out put has proper messages for each section, hope you find it helpfull
-Thank You