0% found this document useful (0 votes)
35 views2 pages

#Include Int Int While

The document contains 4 code snippets that: 1) Read integer inputs from the user and calculate their sum and number of inputs. 2) Print a triangle pattern of asterisks where the number of rows is defined by the user. 3) Demonstrate the pre-increment, post-increment, pre-decrement and post-decrement operators on a variable. 4) Read gallons of fuel used and miles driven from the user, calculate miles per gallon each time, and print the overall average.

Uploaded by

Malik Huzaifa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

#Include Int Int While

The document contains 4 code snippets that: 1) Read integer inputs from the user and calculate their sum and number of inputs. 2) Print a triangle pattern of asterisks where the number of rows is defined by the user. 3) Demonstrate the pre-increment, post-increment, pre-decrement and post-decrement operators on a variable. 4) Read gallons of fuel used and miles driven from the user, calculate miles per gallon each time, and print the overall average.

Uploaded by

Malik Huzaifa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
int main()
{
int n=0, count=0, sum = 0;
while (n!=EOF)
{
printf("Input Integer:");
scanf_s("%d", &n);
sum = sum + n;
count = count + 1;
}//end of while
printf("The sum of integers entered is: %d\n", sum+1);
system("pause");
}

#include <stdio.h>

int main()
{
int n, c, temp;

printf("Enter number of rows\n");


scanf_s("%d", &n);

do
{

for (temp = n; temp >= 1; temp--)


{
for (c = temp; c >= 1; c--)
printf("*");

printf("\n");

} while (n <= 3 && n >= 15);

system("pause");
}

#include <stdio.h>

int main()
{
int a;

printf("Enter the value of a\n");


scanf_s("%d", &a);
printf("Result:\n");
printf("The value of a is: %d \n", a);
printf("...................\n");
printf("The value of ++ a is: %d \n", ++a);
printf("Now the value of a is: %d \n\n", a);
printf("The value of a++ is: %d \n", a++);
printf("Now the value of a is: %d \n\n", a);
printf("The value of -- a is: %d \n", --a);
printf("Now the value of a is: %d \n\n", a);
printf("The value of a-- is: %d \n", a--);
printf("Now the value of a is: %d \n\n", a);

system("pause");
}

#include <stdio.h>
int main()
{
float g=0 ;
float m = 0, new = 0, average = 0;
int count = 0;

while (g != EOF)
{
printf("Enter the gallons used (-1 to end):\n ");
scanf_s("%d", &g);
printf("Enter the miles driven : \n ");
scanf_s("%d", &m);
new = m / g;
printf("The miles / gallons for this tank was %f \n ",new);

count = count + 1;
average = average +new;

}
printf("The overall average miles/gallons was %d\n", average / count);
system("pause");
}

You might also like