ProgramminginC(1)
ProgramminginC(1)
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
void main() void main()
{ {
clrscr(); int a,b,c, sum;
printf(“ADDRESS\n”); float avg;
printf(“Anu\n”); clrscr();
printf(“Al-Azhar College of Arts and Science\n”); printf("Please enter 3 numbers");
printf(“Thodupuzha\n”); scanf("%d%d%d",&a,&b,&c);
getch(); sum=a+b+c;
} avg=(a+b+c)/3;
printf("\nSum is %d", sum);
printf("\nAverage is %f",avg);
getch();
}
Output Output
ADDRESS Please Enter 3 numbers
Anu 5 8 2
Al-Azhar College of Arts and Science Sum is 16
Thodupuzha Average is 5
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<math.h>
void main() #include<conio.h>
{ void main()
float principle, rate, time, simple_interest; {
clrscr() int n,sqr=0,sqroot=0;
printf("Enter the principle :"); clrscr();
scanf("%f", &principle); printf("\nEnter The Number\n");
printf("Enter the rate :"); scanf("%d",&n);
scanf("%f", &rate); sqr=n*n;
printf("Enter the time :"); sqroot=sqrt(n);
scanf("%f", &time); printf("\n SQUARE OF %d is %d .",n,sqr); printf("\n SQU
simple_interest = principle * rate * time / 100; getch();
printf("Simple interest is %0.2f", simple_interest); }
getch()
}
Output Output
Enter the principle :5400 Enter The Number
Enter the rate :8 25
Enter the time :3 SQUARE OF 25 is 625.
Simple interest is 1296.00 SQUARE-ROOT OF 25 IS 5.
printf("\n Enter Second Number : "); // True if the number is perfectly divisible by 2
scanf("%d",&b);
if(number % 2 == 0)
if(a<b) //logical test printf("%d is even.", number);
{ else
printf("\n %d is Smaller",a); printf("%d is odd.", number);
}
else getch();
{ }
printf("\n %d is Smaller",b);
}
getch();
}
Output Output
Enter First Number : 6 Enter an integer
Enter Second Number : 3 5
3 is Smaller 5 is odd.
#include<stdio.h> else
#include<conio.h> printf(" %d is larger",c);
void main()
{ getch();
int a,b,c; }
clrscr();
printf("Enter three numbers\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b) Output
if(a>c) Enter three numbers
printf(" %d is larger",a); 10 3 18
else 18 is larger.
printf(" %d is larger",c);
else
if(b>c)
printf(" %d is larger",b);
Output Output
Enter any number: Enter any number:
14 121
Number is POSITIVE Given number is a palindrome number
10. Write a C program to check whether the given number is Armstrong or not?
#include<stdio.h> if(sum==temp)
int main(){ printf("%d is an Armstrong number",temp);
int num,r,sum=0,temp; else
printf("Enter a number: "); printf("%d is not an Armstrong number",temp);
scanf("%d",&num); return 0;
temp=num; }
while(num!=0)
{
r=num%10; Output
num=num/10; Enter a number: 153
sum=sum+(r*r*r); 153 is an Armstrong number
}
11. Write a C program to check whether 12. Write a C program to find the sum of
the given number is prime or not? digits of a number.
Output Output
Enter a positive integer: 13 Enter any number to find sum of its digit:
13 is a prime number. 123
Sum of digits = 6
14. Write a C program to generate 15. Write a C program to find the factorial
Fibonacci series upto the limit. of a number using function.
Output Output
Enter the limit: 10 Enter an integer number: 7
Fibonacci series up to the given limit are: Factorial of 7 is = 5040
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
a)Function with arguments and return value. b) Function with arguments and without return
value.
#include <stdio.h> #include <stdio.h>
int add(int a,int b); void add(int a,int b);
void main() void main()
{ {
int num1,num2,sum=0; int num1,num2;
c) Function without arguments and with return d) Function without arguments and without
value. return value.
#include <stdio.h> #include <stdio.h>
int add(); void add();
void main() void main()
{ {
int sum=0; add();
sum=add(); }
printf("Sum =%d",sum); void add()
} {
int add() int result,num1,num2;
{ printf("Enter two numbers\n");
int result,num1,num2; scanf("%d%d",&num1,&num2);
printf("Enter two numbers\n"); result=num1+num2;
scanf("%d%d",&num1,&num2); printf("Sum =%d",result);
result=num1+num2; }
return result;
}
Output Output
Enter two numbers Enter two numbers
30 20
20 25
Sum = 50 Sum = 45
printf("\n");
#include<stdio.h> }
int main() { return (0);
int i, j, mat1[10][10], mat2[10][10], mat3[10][10]; }
int row1, col1, row2, col2;
#include<stdio.h> Output
#include<stdlib.h> 1. Find Length
#include<string.h> 2. Concatenate
int main(){ 3. Compare
char string1[20], string2[20]; //string variables 4. Copy
declaration with size 20 5. Exit
int choice;
while(1){ Enter your choice: 1
printf("\n1. Find Length \n2. Concatenate \n3.
Compare \n4. Copy \n5. Exit\n"); Enter the string: alazhar
printf("Enter your choice: "); The length of string is 7
scanf("%d",&choice);
switch(choice){ 1. Find Length
case 1: 2. Concatenate
printf("Enter the string: "); 3. Compare
scanf("%s",string1); 4. Copy
printf("The length of string is %d", 5. Exit
strlen(string1)); Enter your choice: 2
break;
case 2: Enter two strings: alazhar
printf("Enter two strings: "); college
scanf("%s%s",string1,string2);
strcat(string1,string2); The concatenated string is alazharcollege
printf("The concatenated string is %s", string1);
break; 1. Find Length
case 3: 2. Concatenate
printf("Enter two strings: "); 3. Compare
scanf("%s%s",string1,string2); 4. Copy
if(strcmp(string1,string2)==0){ 5. Exit
printf("They are equal"); Enter your choice: 3
}else{
printf("They are not equal"); Enter two strings: thodupuzha
} kerala
break; They are not equal
case 4: 1. Find Length
printf("Enter a string: "); 2. Concatenate
scanf("%s",string1); 3. Compare
printf("String1 = %s\n",string1); 4. Copy
printf("After copying string1 to string 2\n"); 5. Exit
strcpy(string2,string1); Enter your choice: 4
printf("String2 = %s",string2); Enter a string: alazhar
break; String1 = alazhar
case 5: After copying string1 to string 2
exit(0); String2 = alazhar
} 1. Find Length
} 2. Concatenate
return 0; 3. Compare
} 4. Copy
5. Exit
Enter your choice: 5