C Programming Project
C Programming Project
Project on “Programming In C”
Output:
Give the 1st number
The avarage is = 5
2. c program to calculate simple interest.
int main()
{
float amount,rate,time,si;
si=(amount*rate*time)/100;
return 0;
}
Output
int main()
{
int a ;
//input age
printf("Enter the age of the person: ");
scanf("%d",&a);
return 0;
}
Output
First run:
Enter the age of the person: 21
Eigibal for voting
Second run:
Enter the age of the person: 15
Not eligibal for voting
4. C program to convert temperature from Fahrenheit
to Celsius and Celsius to Fahrenheit.
#include <stdio.h>
int main()
{
float fh,cl;
int choice;
if(choice ==1){
printf("\nEnter temperature in Fahrenheit: ");
scanf("%f",&fh);
cl= (fh - 32) / 1.8;
printf("Temperature in Celsius: %.2f",cl);
}
else if(choice==2){
printf("\nEnter temperature in Celsius: ");
scanf("%f",&cl);
fh= (cl*1.8)+32;
printf("Temperature in Fahrenheit: %.2f",fh);
}
else{
printf("\nInvalid Choice !!!");
}
return 0;
}
Output
First Run:
1: Convert temperature from Fahrenheit to Celsius.
2: Convert temperature from Celsius to Fahrenheit.
Enter your choice (1, 2): 1
Second Run:
1: Convert temperature from Fahrenheit to Celsius.
2: Convert temperature from Celsius to Fahrenheit.
Enter your choice (1, 2): 2
#include <stdio.h>
int main(){
char ch;
int asciiValue;
asciiValue=(int)ch;
Output
#include <stdio.h>
int main(void) {
int n, sum;
//input value of n
printf("Enter the value of n: ");
scanf("%d", &n);
//print sum
printf("sum = %d\n", sum);
return 0;
}
Output
Run1:
Enter the value of n: 5
sum = 15
Run2:
Enter the value of n: 10
sum = 55
7. C program to find factorial of a number.
#include <stdio.h>
int main()
{
int num,i;
long int fact;
printf("\nFactorial of %d is = %ld",num,fact);
return 0;
}
Output
Factorial of 7 is = 5040
8. C program to print all prime numbers from 1 to N.
#include <stdio.h>
int main()
{
int i, n;
return 0;
}
Output:
#include <stdio.h>
int main()
{
int wDay;
switch(wDay)
{
case 0:
printf("Sunday");
break;
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
default:
printf("Invalid weekday number.");
}
printf("\n");
return 0;
}
Output
First Run:
Enter weekday number (0-6): 3
Wednesday
Second run:
Enter weekday number (0-6): 9
Invalid weekday number.
10.C program to print indexes of a particular character
in a string
#include <stdio.h>
int main()
{
char str[30],ch;
int ind[10],loop,j;
j=0;
for(loop=0; str[loop]!='\0'; loop++)
{
if(str[loop]==ch)
ind[j++]=loop;
}
return 0;
}
Output
Enter string: Hi there, how are you?
Enter character: o
Input string is: Hi there, how are you?
Indexes: 11 19
11. C program to capitalize first character of each word
in a string.
#include <stdio.h>
#define MAX 100
int main()
{
char str[MAX]={0};
int i;
//input string
printf("Enter a string: ");
scanf("%[^\n]s",str); //read string with spaces
return 0;
}
Output
Enter a string: HELLO FRIENDS HOW ARE YOU?
Capitalize string is: Hello Friends How Are You?
12. C program to remove all spaces from a given string
#include <stdio.h>
// main function
int main()
{
// declare a char buffer
char string[100]={0};
remove_spaces(string , len);
Output
Run 1 :
Enter your string : C is the master of all
New string is : Cisthemasterofall
Run 2 :
Enter your string : I love myself
New string is : Ilovemyself
13. C program to print fibonacci series using recursion
#include <stdio.h>
Output
return 0;
}
Output
For array_2 : 3
for(int i=0;i<n;i++){
//for the last element in the modified array
//it will be starting elemnt
if(i==n-1)
a[i]=temp;
//for other element shift left
else
a[i]=a[i+1];
}
return a;
}
int main()
{
int n;
return 0;
}
Output
int main()
{
int n, i, j, t; //n is representing number of the output box
//input n
printf("Enter the value of n: ");
scanf("%d", &n);
t = 2 * n - 1;
i = t; //i and j are the number of rows and columns of the box.
j = t;
First run:
Enter the value of n: 2
2 2 2
2 1 2
2 2 2
Second run:
Enter the value of n: 4
4 4 4 4 4 4 4
4 3 3 3 3 3 4
4 3 2 2 2 3 4
4 3 2 1 2 3 4
4 3 2 2 2 3 4
4 3 3 3 3 3 4
4 4 4 4 4 4 4
int main()
{
int num1,num2;
printf("Enter value of num1: ");
scanf("%d",&num1);
printf("Enter value of num2: ");
scanf("%d",&num2);
//print values before swapping
printf("Before Swapping: num1=%d, num2=%d\n",num1,num2);
//call function by passing addresses of num1 and num2
swap(&num1,&num2);
//print values after swapping
printf("After Swapping: num1=%d, num2=%d\n",num1,num2);
return 0;
}
Output
int cnt1 = 0;
int cnt2 = 0;
int flg = 0;
fp1 = fopen(argv[1],"r");
if( fp1 == NULL )
{
printf("\n%s File can not be opened : \n",argv[1]);
return -1;
}
fp2 = fopen(argv[2],"r");
if( fp2 == NULL )
{
printf("\n%s File can not be opened : \n",argv[2]);
return -1;
}
fseek(fp1,0,SEEK_SET);
fseek(fp2,0,SEEK_SET);
fclose(fp1);
fclose(fp2);
return 0;
}
Output
int main()
{
int arr[10];
int sum,product,i;
return 0;
}
Output
Enter elements :
Enter arr[0] : 11
Enter arr[1] : 22
Enter arr[2] : 3
Enter arr[3] : 4
Enter arr[4] : 5
Enter arr[5] : 66
Enter arr[6] : 7
Enter arr[7] : 8
Enter arr[8] : 9
Enter arr[9] : 10
/*function declarations*/
int sumTwoNum(int, int); /*to get sum*/
float averageTwoNum(int, int); /*to get average*/
int main()
{
int number1, number2;
int sum;
float avg;
/*function calling*/
sum = sumTwoNum(number1, number2);
avg = averageTwoNum(number1, number2);
return 0;
}
}
float averageTwoNum(int x, int y)
{
/*x and y are the formal parameters*/
float average;
return ((float)(x) + (float)(y)) / 2;
Output: