C programs for Practice

Unformatted text preview:

Write a C program to generate Fibonacci series include stdio h int main int i n initialize first and second terms int t1 0 t2 1 initialize the next term 3rd term int nextTerm t1 t2 printf Enter the number of terms scanf d n print the first two terms t1 and t2 printf Fibonacci Series d d t1 t2 print 3rd to nth terms for i 3 i n i printf d nextTerm t1 t2 t2 nextTerm nextTerm t1 t2 return 0 1 Write a C program to check a number palindrome is not include stdio h int main int number reverse 0 original remainder printf Enter a number scanf d number original number while number 0 remainder number 10 reverse reverse 10 remainder number number 10 if original reverse printf d is a palindrome number n original else printf d is not a palindrome number n original return 0 2 Write a C program to check a given number prime number or not include stdio h int main int number i int isPrime 1 Assume the number is prime Prompt user for input printf Enter a number n scanf d number Check if the number is less than or equal to 1 if number 1 printf d is not a prime number n number return 0 Exit the program Check for factors from 2 to number 1 for i 2 i number i if number i 0 isPrime 0 Found a factor so it s not prime break No need to check further Output the result if isPrime printf d is a prime number n number else printf d is not a prime number n number return 0 Indicate that the program finished successfully 3 Write a C program to reverse a string using the standard library function include stdio h include string h int main char str 50 helloworld printf The given string is s n str printf After reversing string is s strrev str return 0 Write a C program to reverse a string without using the standard library function include stdio h include string h Function to reverse a string void reverseString char str int n strlen str for int i 0 i n 2 i Swap characters char temp str i str i str n i 1 str n i 1 temp int main char str 50 geeksforgeeks printf The given string is s n str Reverse the string reverseString str printf After reversing the string is s n str return 0 Indicate successful completion 4 Write a C program to display the sum of digits of an integer value include stdio h int main int n sum 0 m printf Enter a number scanf d n while n 0 m n 10 sum sum m n n 10 printf Sum is d sum return 0 5 Write a C program to display Factorial of a Number include stdio h int main int n i unsigned long long fact 1 printf Enter an integer scanf d n shows error if the user enters a negative integer if n 0 printf Error Factorial of a negative number doesn t exist else for i 1 i n i fact i printf Factorial of d llu n fact return 0 6 Write a C program to print full pyramid include stdio h int main int rows Prompt user for the number of rows printf Input number of rows scanf d rows Loop through each row for int i 1 i rows i Print spaces for int j 1 j rows i j printf Print space Print stars for int k 1 k i k printf Print star Move to the next line printf n return 0 Indicate successful completion 7


View Full Document

C programs for Practice

Download C programs for Practice
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view C programs for Practice and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view C programs for Practice and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?