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

11practice Assignment 1

The document contains 7 C programming problems assigned as practice to a student named Nitesh Kumar Yadav. Each problem is numbered and includes the code to write a program to solve that problem such as writing a program to print the table of a given number, find prime numbers between 1 to n, determine if a number is a palindrome, and more.

Uploaded by

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

11practice Assignment 1

The document contains 7 C programming problems assigned as practice to a student named Nitesh Kumar Yadav. Each problem is numbered and includes the code to write a program to solve that problem such as writing a program to print the table of a given number, find prime numbers between 1 to n, determine if a number is a palindrome, and more.

Uploaded by

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

Practice Assignment 1

Name: Nitesh Kumar Yadav


Reg. No.: 20195103
Group: B1

1. Write c program to implement the table of any number.

#include<stdio.h>

int main()
{
int n, i;
printf("Enter a number: ");
scanf("%d", &n);
for (i = 1; i <= 10; i++)
{
printf("%d * %d = %d \n", n, i, n * i);
}
}

2. Write c program to implement the Fibonacci Series.


e.g. 0 1 1 2 3 5 8 13 21 .…

#include<stdio.h>
int main()
{
int i, n, t1 = 0, t2 = 1, a;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");

for (i=1;i<=n;i++)
{
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = a;
}
}

3. Write c program to find prime numbers between 1 to n numbers.

#include<stdio.h>

int main()
Practice Assignment 1
{
int i,j,n;

printf("Enter number to print prime numbers\n");


scanf("%d",&n);

printf("Prime numbers are:-\n");


for(i=2;i<=n;i++)
{
int c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
c++;
}
}

if(c==2)
{
printf("%d ",i);
}
}
}

4. Write c program to find the Armstrong number.

#include <stdio.h>
int main()
{
int num, original, rem, sum = 0;
//rem is remainder and original is the original number
printf("Enter a three-digit Number: ");
scanf("%d", &num);
original = num;
while(original != 0)
{
rem = original%10;
sum =sum + rem*rem*rem;
original=original/ 10;
}
if(sum == num)
printf("%d is an Armstrong number.",num);
else
printf("%d is not an Armstrong number.",num);

}
Practice Assignment 1
5. Write c program to reverse a number.

#include<stdio.h>
int main()
{
int n, rev = 0, rem;
printf("Enter an integer: ");
scanf("%d", &n);
while (n != 0) {
remainder = n % 10;
rev = rev * 10 + rem;
n /= 10;
}
printf("Reversed number = %d", rev);

6. Write c program to find out the sum of N numbers.

#include <stdio.h>
int main()
{
int n, i, sum = 0;

printf("Enter number: ");


scanf("%d", &n);

for (i=1;i<=n;i++)
{
sum += i;
}

printf("Sum= %d",sum);
}

7. Write c program to find a palindrome number.

#include <stdio.h>
int main()
{
int n, r = 0, t;

printf("Enter a number to check it’s palindrome or not:\n");


scanf("%d", &n);
Practice Assignment 1
t = n;

while (t != 0)
{
r = r * 10;
r = r + t%10;
t = t/10;
}

if (n == r)
printf("%d is a palindrome number.\n", n);
else
printf("%d isn't a palindrome number.\n", n);

You might also like