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

Looping Statements in C Programming

Uploaded by

Taaha Baig
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)
25 views2 pages

Looping Statements in C Programming

Uploaded by

Taaha Baig
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

3 Looping Statements

a. To find the sum of first N natural numbers using While loop.


b. Check whether the number is palindrome or not using For loop

3. [Link] find the sum of first N natural numbers using


While loop.

#include <stdio.h>

int main() {
int N, sum = 0, i = 1;

printf("Enter the value of N: ");


scanf("%d", &N);

while (i <= N) {
sum = sum + count;
i++;
}

printf("The sum of the first %d natural numbers is: %d\n", N, sum);

return 0;
}

3. [Link] whether the number is palindrome or not


using For loop.

#include <stdio.h>

int main() {
int num, temp, rev, rem;

printf("Enter a number: ");


scanf("%d", &num);

temp = number;

for (rev=0; num != 0; num /= 10) {


rem = num % 10;
rev = rev * 10 + rem;
}

if (temp == rev) {
printf("%d is a palindrome number.\n", temp);
} else {
printf("%d is not a palindrome number.\n", temp);
}

return 0;
}

You might also like