0% found this document useful (0 votes)
14 views4 pages

Lab Work

The document contains multiple C programming code snippets demonstrating various programming concepts such as calculating sums using loops, finding squares of numbers within a range, and determining the largest number from user input. Each code block includes comments and print statements for clarity. The overall focus is on basic control structures like while, do-while, and for loops.

Uploaded by

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

Lab Work

The document contains multiple C programming code snippets demonstrating various programming concepts such as calculating sums using loops, finding squares of numbers within a range, and determining the largest number from user input. Each code block includes comments and print statements for clarity. The overall focus is on basic control structures like while, do-while, and for loops.

Uploaded by

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

1

#include<stdio.h>

int main(){
int num1=0;
int sum =0;

while (num1 < 10)


{
num1 = num1 + 1;
sum = sum + num1;
printf("%d\n",num1);
}
printf("the sum is %d",sum);

printf("\n");
/*
while (num1 < 10)
{
printf("%d\n",num1+1 );
num1 = num1 + 1;
sum= num1+sum;
} printf("the sum is %d",sum);
*/

2
do
{
int num1=1;
/* code */
num1 = num1 ;
sum = sum + num1;
printf("%d\n",num1);
}
while (num1 < 10);
printf("the sum isfor do while %d",sum);
return 0;
}
3

#include<stdio.h>

int main(){
/*find theh sum of 9+11+13+15-----+57+59 */

int count=9;
int sum=0;
while(count<=59){
sum=sum+count;
count=count+2;
}
printf("the sum for the while %d\n",sum);

printf("\n");

4
do
{
sum=sum+count;
count=count+2;
} while (count<=59);
printf(" the sum for the do while %d",sum);

return 0;
}
5

#include <stdio.h>

int main() {
int lower;
int upper;
int counter;
int squr;

printf("Enter the lower limit: ");


scanf("%d", &lower);
printf("Enter the upper limit: ");
scanf("%d", &upper);

for (counter = lower; counter <= upper; counter++) {


squr = counter * counter;
printf("%d\n", squr);
}

return 0;
}

6
#include<stdio.h>

int main(){
//find the largest number after get 10 numbers from the user

int largest,count,num;
count = 0;

printf("enter the value1: ");


scanf("%d",&num);
largest = num;
for (count =1; count<10; count++)
{
printf("enter value %d: " ,count +1);
scanf("%d",&num);

if (num> largest)
{
largest= num;
}
}
printf("largest is %d",largest);
return 0;
}

You might also like