CPPM_Journal[1]
CPPM_Journal[1]
#include <stdio.h>
#include<conio.h>
void main()
{
int num, r, sum = 0, t;
clrscr();
printf("Enter a number: ");
scanf("%d",&num);
for(t=num;num!=0;num=num/10){
r=num % 10;
sum=sum*10+r;
}
if(t==sum)
printf("%d is a palindrome number.\n",t);
else
printf("%d is not a palindrome number.\n",t);
getch();
Output
2) Write a C program that replaces given word with new word in a sentence.
// Write a program to replace a word from a sentence
#include <stdio.h>
#include <conio.h>
void main()
{
char s1[80], w[20], ch, sw[20], rw[20];
int i, k;
clrscr();
printf("\nOutput = ");
strcat(s1, " ");
k = 0;
for (i = 0; s1[i] != '\0'; i++)
{
ch = s1[i];
if (ch != ' ')
{
w[k] = ch;
k++;
}
else
{
w[k] = '\0';
// printf("\n %s",w);
k = 0;
if (strcmp(w, sw) == 0)
{
// strcat(rw," ");
printf("%s ", rw);
}
else
{
// strcat(w," ");
printf("%s ", w);
}
}
}
getch();
}
Output
3) Write a menu driven program to calculate area of Square, Triangle, Rectangle and Circle. (Use
concept of ‘switch’).
#include<stdio.h>
#include<conio.h>
#define PI 3.147
void main()
{
float radius, length, breadth;
float base, height, area;
int choice;
clrscr();
printf("Enter\n");
printf(" 1. To find area of triangle\n 2. To find area of Square\n");
printf(" 3. To find area of circle\n 4. To find area of rectangle\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf(" Enter base and height of a triangle\n");
scanf("%f %f", &base, &height);
break;
case 2:
printf(" Enter length of a Square\n");
scanf("%f", &length);
break;
case 3:
printf(" Enter the radius of a Circle\n");
scanf("%f", &radius);
break;
case 4:
printf(" Enter the length and breadth of a Rectangle\n");
scanf("%f %f", &length, &breadth);
break;
default:
printf(" Invalid Choice\n");
}
getch();
}
Output
4) Write a menu driven program that perform arithmetic operations (+, –, *, /) according to
user’s choice.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
int op;
clrscr();
printf(" 1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n");
printf("Enter the values of a & b: ");
scanf("%d %d",&a,&b);
printf("Enter your Choice : ");
scanf("%d",&op);
switch(op)
{
case 1 :
printf("Sum of %d and %d is : %d",a,b,a+b);
break;
case 2 :
printf("Difference of %d and %d is : %d",a,b,a-b);
break;
case 3 :
printf("Multiplication of %d and %d is : %d",a,b,a*b);
break;
case 4 :
printf("Division of Two Numbers is %d : ",a/b);
break;
default :
printf(" Enter Your Correct Choice.");
break;
}
getch();
}
Output
5) Write a program to check whether the number is prime or not.
#include <stdio.h>
#include <conio.h>
void main()
{
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
if (n == 0 || n == 1)
flag = 1;
if (n % i == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
getch();
}
Output
6) Write a program to input number through keyboard and check whether the number is
Armstrong number or not
#include <stdio.h>
#include<conio.h>
void main() {
int num, originalNum, remainder, result = 0;
clrscr();
while (originalNum != 0) {
remainder = originalNum % 10;
result += remainder * remainder * remainder;
originalNum /= 10;
}
if (result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
getch();
}
Output
7) Write a program to display Fibonacci series up to 8 steps.
#include <stdio.h>
#include <conio.h>
void main()
{
int i, n;
int t1 = 0, t2 = 1;
clrscr();
getch();
}
Output
8) Write a c program to print an array of 10 elements in ascending order
#include<stdio.h>
#include<conio.h>
void main()
{
int i, arr{1,2,3,4,5,6,7,8,9,10};
clrscr();
for(i=0;i<10;i++)
{
printf("%d",arr[i])
}
getch();
}
Output
9) Write a program to print Following pattern: N=4
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, k, t = 0;
clrscr();
for (i = 1; i <= 4; i++)
{
for (k = t; k < 4; k++)
{
printf(" ");
}
for (j = 0; j < i; j++)
{
printf(" * ");
t = t + 1;
}
printf("\n");
}
getch();
}
Output
10) Write a program to count characters in the string. E. g. Input String:
BCA College Total Characters: 11
#include <stdio.h>
#include <string.h>
void main()
{
char string[] = "C is Fun";
int i, count = 1;
clrscr();
getch();
}
Output
11) Write a program to calculate sum of each digit of a given number.
#include <stdio.h>
#include<conio.h>
void main()
{
int num, sum = 0;
while (num != 0)
{
sum += num % 10;
num = num / 10;
}
getch();
}
Output
NAME : GOPAL PATIL
SUBJECT : CPPM
FY.BCA