Harshitha - Colaboratory
Harshitha - Colaboratory
#include<stdio.h>
int main()
{
int i, num, sum = 0;
printf("enter a number");
scanf("%d", &num);
if(sum == num)
{
printf("perfect number\n");
}
else
{
printf("not a perfect number\n");
}
return 0;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 1/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main() {
int i, n;
int t1 = 0, t2 = 1;
int nextTerm = t1 + t2;
scanf("%d", &n);
printf("%d, %d, ", t1, t2);
return 0;
}
Write a C program to find Greatest Common Divisor (GCD) of given two numbers
#include<stdio.h>
int main()
{
int n1, n2, gcd = 1;
scanf("%d%d",&n1,&n2);
for(int i = 1; i <= n1 || i <= n2; i++) {
if(n1 % i == 0 && n2 % i == 0)
gcd = i;
}
printf("%d",gcd);
return 0;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 2/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main() {
int n, n1, rev = 0, rem;
if (n1 == rev){
printf("palindrome");
}
else{
printf("not palindrome");
}
return 0;
}
#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
scanf("%c", &c);
if (lowercase_vowel || uppercase_vowel)
printf("vowel");
else
printf("consonant");
return 0;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 3/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main() {
int num, i;
scanf("%d", &num);
for (i = 1; i <= num; ++i) {
if (num % i == 0) {
printf("%d, ", i);
}
}
return 0;
}
#include<stdio.h>
int main(){
int a,b=1;
scanf("%d",&a);
for(int i = 1; i<=a;i++)
{
b=b*i;
}
printf("%d",b);
return 0;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 4/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main() {
int n, i, flag = 0;
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);
return 0;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 5/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main()
{
int n, t, sum = 0, remainder;
t = n;
if (n>=100 && n<1000){
while (t != 0)
{
remainder = t % 10;
sum = sum + remainder;
t = t / 10;
}
printf("The sum of the digits of %d is %d.\n", n, sum);
}
else{
printf("The number %d is not a three-digit number.", t);
}
return 0;
}
Write a C program to print your roll no, date of birth, and mobile number.
#include <stdio.h>
int main(){
int roll, date, month, year;
long int mobile;
scanf("%d%d-%d-%d%ld", &roll, &date, &month, &year, &mobile);
printf("Roll no: %d\n",roll);
printf("Date of Birth: %d-%d-%d\n",date,month,year);
printf("Mobile no: %ld\n", mobile);
return 0;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 6/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
#include <stdio.h>
int main()
{
int a,b,flag;
scanf("%d%d",&a,&b);
while(a<b){
flag=0;
if (a<=1){
++a;
continue;
}
for (int i=2;i<=a/2;++i){
if (a%i==0){
flag =1 ;
break;
}
}
if(flag==0)
printf("%d ", a);
a++;
}
return 0;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 7/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main() {
int i, j;
char input, alphabet = 'A';
printf("Enter an uppercase character you want to print in the last row: ");
scanf("%c", &input);
for (i = 1; i <= (input - 'A' + 1); ++i) {
for (j = 1; j <= i; ++j) {
printf("%c ", alphabet);
}
++alphabet;
printf("\n");
}
return 0;
}
Write a C program to calculate the distance between the two points (x1,y1) and (x2, y2).
#include <stdio.h>
#include <math.h>
int main() {
int x1, y1, x2, y2;
float gd;
scanf("%d", &x1);
scanf("%d", &y1);
scanf("%d", &x2);
scanf("%d", &y2);
gd= sqrt(pow((x2-x1),2)+(pow((y2-y1),2)));
printf("The distance between two points (%d,%d) and (%d,%d) is %.2f", x1,y1,x2,y2,gd)
printf("\n");
return 0 ;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 8/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
#include <math.h>
return bin;
}
Write a C program to print a given number for a given number of times using for loop.
#include <stdio.h>
#include <stdio.h>
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 9/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
#include<stdio.h>
int main(){
char c;
char lower,upper;
scanf("%c",&c);
if(c>=65&&c<97)
{
lower=c+32;
printf("%c", lower);
}
else
{
upper=c-32;
printf("%c",upper);
}
return 0;
}
Write a C program to input value of 'N' and find sum of all odd numbers 1 to 'N'
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 10/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main()
{
int i, n, sum=0;
scanf("%d", &n);
printf("%d", sum);
return 0;
}
Write a C Program to Print even and odd numbers in a given range using functions
#include<stdio.h>
int main()
{
int i,n,l,even=0,odd=0;
printf("enter lower limit and upper limit values to display even and odd numbers");
scanf("%d%d",&n, &l);
printf("\neven numbers are");
for(i=n;i<=l;i++)
{
if(i%2==0)
{
printf("\n%d",i);
even++;
}
}
printf("\n\nodd numbers are");
for(i=n;i<=l;i++)
{
if(i%2==1)
{
printf("\n%d",i);
odd++;
}
}
return 0;
}
Write a C program that accepts three items’ weights (floating points' values ) and a number of
purchases (floating points' values) and calculate the average value of the items.
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 11/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main() {
float num1, num2,num3,num4, average;
scanf("%f%f%f%f", &num1,&num2,&num3,&num4);
return 0;
}
#include <stdio.h>
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 12/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include<stdio.h>
int main()
{
int fact=1,sum=0;
int n1,n2,r;
printf("Enter the lower limit to find strong number:\n");
scanf("%d",&n1);
printf("Enter the upper limit to find strong number:\n");
scanf("%d",&n2);
printf("All strong numbers between 1 to 100 are:\n");
for(int i=n1;i<=n2;i++)
{
int k=i;
while(k!=0)
{
r=k%10;
fact=factorial(r);
k=k/10;
sum=sum+fact;
}
if(sum==i){
printf("%d, ",i);
}
sum=0;
}
return 0;
}
int factorial(int f)
{
int mul=1;
for(int i=1; i<=f;i++)
{
mul=mul*i;
}
return mul;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 13/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
#include<stdio.h>
int main(){
int a;
scanf("%d",&a);
for (int i=1;i<=10;i++)
printf("%d\t*\t%d\t=\t%d\n", a,i,a*i);
}
#include <stdio.h>
int main()
{
int n, t, sum = 0, remainder;
scanf("%d", &n);
t = n;
while (t != 0)
{
remainder = t % 10;
sum = sum + remainder;
t = t / 10;
}
printf("%d\n",sum);
return 0;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 14/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include<stdio.h>
printf("%d", sum);
}
Write a C program that accepts an employee's ID, totally worked hours of a month, and the
amount he received per hour. Print the employee's ID and salary for a particular month.
#include<stdio.h>
int main(){
int emp;
float hours,aph;
scanf("%d%f%f",&emp,&hours,&aph);
printf("Emp no : %d\n",emp);
printf("Salary for the month : %.2f",hours*aph);
return 0;
}
#include <stdio.h>
int main()
{
int side1, side2, side3;
printf("Enter the lengths of the three sides of the triangle:\n");
scanf("%d", &side1);
scanf("%d", &side2);
scanf("%d", &side3);
if (side1 == side2 == side3) printf("The triangle is equilateral");
else if (side1 == side2 || side1 == side3 || side2 == side3) printf("The triangle is
else printf("Te triangle is scalene");
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 15/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main()
{
int x;
printf("Enter year: ");
scanf("%d", &x);
#include <stdio.h>
int main()
{
int n1, n2, n3, min;
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 16/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
if (number % 5 == 0 && number % 11 == 0)
{
printf("%d is divisible by both 5 and 11\n", number);
}
else
{
printf("%d is not divisible by both 5 and 11\n", number);
}
}
#include <stdio.h>
int main()
{
int num;
printf("Enter a number: ");
scanf("%d", &num);
switch (num > 0)
{
case 1:
printf("Positive number\n");
break;
case 0:
switch (num < 0)
{
case 1:
printf("Negative number\n");
break;
case 0:
printf("Zero\n");
break;
}
break;
}
}
Design a calculator that performs arithmetic operations on two numbers using switch case
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 17/21
11/28/23, 10:01 PM Harshitha - Colaboratory
#include <stdio.h>
int main() {
char operation;
double num1, num2, result;
while (1)
{
printf("Enter an arithmetic operation (+, -, *, /) or 'q' to quit: ");
scanf(" %c", &operation);
switch (operation)
{
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0)
{
result = num1 / num2;
}
else
{
printf("Division by zero is not allowed.\n");
continue; // Skip to the next iteration
}
break;
default:
printf("Invalid operation. Try again.\n");
continue; // Skip to the next iteration
}
return 0;
}
#include <stdio.h>
#include <math.h>
int main()
{
int a, b, c, disc, *r1, *r2;
printf("Enter coefficients a, b and c for ax^2 + bx + c = 0 ");
scanf("%d %d %d", &a, &b, &c);
discriminant = b * b - 4 * a * c;
if (disc == 0) {
printf("both roots are equal, ie: %d\n", *r1);
} else {
printf("Real roots: %d and %d\n", *r1, *r2);
}
}
}
%%file factorial.cpp
#include <stdio.h>
int main()
{
int n;
unsigned long long factorial = 1;
return 0;
}
#include <stdio.h>
int main()
{
int num, reversed = 0, original;
printf("Enter an integer: ");
scanf("%d", &num);
original = num;
while (num > 0)
{
reversed = reversed * 10 + num % 10;
num /= 10;
}
if (original == reversed)
{
printf("%d is a palindrome\n", original);
} else {
printf("%d is not a palindrome\n", original);
}
return 0;
}
#include <stdio.h>
int main()
{
int rows = 4;
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 20/21
11/28/23, 10:01 PM Harshitha - Colaboratory
%%file abcde.cpp
#include <stdio.h>
int main()
{
int rows=5;
char alphabet = 'A';
return 0;
}
https://colab.research.google.com/drive/1nlx9Wn19vjbGmzGJQZzyhZrPvB_ri1rp#scrollTo=JVen_neFwlKb&printMode=true 21/21