0% found this document useful (0 votes)
8 views6 pages

C Programming

The document contains a series of C programming exercises spread over four days, showcasing various coding tasks such as printing 'hello world', swapping numbers, checking for prime numbers, generating Fibonacci series, calculating factorials, reversing numbers, and checking for palindromes. Each code snippet is accompanied by explanations and user input prompts. The exercises progressively build on fundamental programming concepts in C.
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)
8 views6 pages

C Programming

The document contains a series of C programming exercises spread over four days, showcasing various coding tasks such as printing 'hello world', swapping numbers, checking for prime numbers, generating Fibonacci series, calculating factorials, reversing numbers, and checking for palindromes. Each code snippet is accompanied by explanations and user input prompts. The exercises progressively build on fundamental programming concepts in C.
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

C programming

Day 1
Code 1 : hello world

#include <stdio.h>

Int main(){

Printf(“hello world”);

Code 2 : swap two numbers without third variable

#include <stdio.h>
int main() {

int a=7,b=8;

a=a+b;

b=a-b;

a=a-b;

printf("the calculated number is a= %d b=%d",a,b);

return 0;
}
Day 2
Code 3 : check whether the number is prime or not
#include <stdio.h>

int main(){

int a;

printf("enter a number" );

scanf("%d",&a);

if(a<=0){

printf("number is not prime");

for(int i=2;i<a;i++){

if(a%i==0){

printf("number is not a prime");

printf("number is prime");

return 0;

Code 4 : print fibonacci series upto n


#include <stdio.h>

int main() {

int a;

printf("enter the number of fibonnaci required " );

scanf("%d",&a);

if(a==1){

printf("%d",0);

if(a==2){

printf("%d",0);

printf("%d",1);
}

else if (a>2){

printf("%d\n",0);

//printf("%d\n",1);

for(int i=2;i<=a;i++){

int next=(i-1)+(i-2);

printf("%d\n",next);

Day 3
Code 5 : find factorial
int main() {

int a,fact=1;

printf("enter the number of factorial required " );

scanf("%d",&a);

if(a<0){

printf("factorial is not present");

}else if(a==0){

printf("factorial is 1");

}else{

for(int i=1;i<=a;i++){

fact=fact*i;

printf("%d ",fact);

printf("\nfactorial of %d is %d",a,fact);

}
Code 6:

#include <stdio.h>

int factorial(int a) {

if (a == 0)

return 1;

else

return a * factorial(a - 1);

int main() {

int a;

printf("Enter the number for factorial: ");

scanf("%d", &a);

if (a < 0) {

printf("Factorial not defined for negative numbers.\n");

} else {

printf("The factorial of %d is %d\n", a, factorial(a));

return 0;

Day 4
Code 7 Reverse the number
#include <stdio.h>
#include<math.h>

int main()
{
int number,reversedNumber=0,digit;

//int orginalnum=number;

printf("enter a number");

scanf("%d",&number);
int orginalnum=number;

while(number!=0){

digit=number%10;

reversedNumber=reversedNumber*10+digit;

number=number/10;

printf("The reversedNumber of %d is %d",orginalnum,reversedNumber);


return 0;
}

Code 8 Check for palindrome


#include <stdio.h>

#include<math.h>

int main()

int number,reversedNumber=0,digit;
//int orginalnum=number;

printf("enter a number");

scanf("%d",&number);

int orginalnum=number;

while(number!=0){

digit=number%10;

reversedNumber=reversedNumber*10+digit;

number=number/10;
}
if(orginalnum==reversedNumber){

printf("entered number %d is pallindrome",orginalnum);

}else{

printf("entered number %d is not a pallindrome",orginalnum);


}

return 0;

You might also like