[go: up one dir, main page]

0% found this document useful (0 votes)
89 views24 pages

Roll No.-101908127 Name-Yuvraj Singh Rathore Group-D2 Assignment I

This document contains the code for several C programs written by a student named Yuvraj Singh Rathore for their assignments. The programs demonstrate basic C concepts like input/output, operators, conditional statements, loops and functions. They include programs to print strings, take user input, calculate simple interest and more. Overall the document shows the student practicing and learning various elements of C programming through short programs and assignments.

Uploaded by

Yuvraj Rathore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views24 pages

Roll No.-101908127 Name-Yuvraj Singh Rathore Group-D2 Assignment I

This document contains the code for several C programs written by a student named Yuvraj Singh Rathore for their assignments. The programs demonstrate basic C concepts like input/output, operators, conditional statements, loops and functions. They include programs to print strings, take user input, calculate simple interest and more. Overall the document shows the student practicing and learning various elements of C programming through short programs and assignments.

Uploaded by

Yuvraj Rathore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 24

Roll No.

-101908127
Name-Yuvraj Singh Rathore
Group-D2
Assignment I
#include <stdio.h>

int main()

{
printf("Hello World\n");
printf("Hello \b World\n");
printf("Hello \t World\n");
printf("Hello World");
}
#include <stdio.h>

int main()
{
printf("See C is Sea\n");
printf("See C is Sea\n");
printf("See C is Sea\n");
printf("See C is Sea\n");
printf("See C is Sea\n");
}
#include <stdio.h>

int main()
{
int a;
float b;
char c;
char d[10];
printf("Enter a Integer\n");
scanf("%d",&a);
printf("Enter a Decimal Number\n");
scanf("%f",&b);
printf("Enter a Character\n");
scanf(" %c",&c);
printf("Enter a 10 Character\n");
scanf(" %s",&d);
printf("Here is your Output \n Integer %i \n Decimal Number %f \n Character %c \n string %s \n"
,a,b,c,d);
}
#include <stdio.h>

int main()
{
printf("First line \t:\t Yuvraj\nSecond line \t;\t 23-C, civil lines\nThird line \t:\t Kanpur\nFourth
line \t:\t UP, 208001");
}
#include <stdio.h>
int main ()
{
int a, b, sum, prod, diff, quot, rem;
puts("Enter two numbers: ");
scanf("%d%d", &a, &b);
sum = a + b;
prod = a * b;
diff = a - b;
quot = a / b;
rem = a%b;
printf("The sum of %d and %d is %d.\n", a, b, sum);
printf("The product of %d and %d is %d.\n", a, b, prod);
printf("The difference of %d and %d is %d.\n", a, b, diff);
printf("The quotient of %d and %d is %d.\n", a, b, quot);
printf("The remainder of %d and %d is %d.\n", a, b, rem);
return 0;
}
#include <stdio.h>
#include <math.h>
int main ()
{
float p,r,t,SI,CI;

printf("Enter Principle, rate and time\n");


scanf("%f%f%f",&p,&r,&t);

SI = (p * r * t)/100;
CI = p*pow((1+r/100),t);

printf("Simple interest of is %f\n",SI);


printf("Compound interest of is %f\n",CI);
}
#include <stdio.h>
#include <math.h>
int main ()
{
float a,b,c,d;
printf("Enter Three Number:\n");
scanf("%f%f%f" ,&a,&b,&c);
d = (a-b)/(b+c);
printf("Value of d is %f \n",d);
}
#include <stdio.h>

int main()
{
float f, c;
printf("Enter Temperature in Celsius to covert it into fahrenheit\n");
scanf("%f", &c);
f = (1.8)*c + 32;
printf("Temperature in fahrenheit is %f \n", f);
}
#include <stdio.h>
#include <math.h>

int main()
{
int a, b, c, s;
float A;
printf("Input three sides of the triangles to compute the area :\n");
scanf("%d%d%d", &a, &b, &c);
s = (a+b+c)/2;
A = sqrt( s*(s-a)*(s-b)*(s-c));
printf("Area is %f \n", A);
}
#include <stdio.h>

int main()
{
float r, a, c;
printf("Enter radius of circle: ");
scanf("%f",&r);
a =3.14f*r*r;
c =2*3.14f*r;
printf("Area of circle: %f \nPerimeter of circle: %f\n",a ,c);
}
Assignment II
#include <stdio.h>
int main()
{
float basic=50000, va, da, hra, gross;
da = basic * 0.5;
hra = basic * 0.2;
va = basic * 0.1;
gross = basic + hra + da + va;
printf("GROSS SALARY OF EMPLOYEE = %f\n", gross);
}
#include <stdio.h>

int main()
{
printf("*****\tLIST OF
ITEMS\t*****\nItems\t\tPrice\ttotal\nPen\t\t10\t20\nPencil\t\t5\t15\nSharpener\t2\t2\nGrand
Total\t17\t37\n");
}
#include <stdio.h>
int main()
{
printf("$\n$\t$\n$\t$\t$\n$\t$\t$\t$\n$\t$\t$\t$\t$");
}
#include <stdio.h>

int main()
{
float a, b;
int sum;
printf("Input two flaoting point numbers:\n");
scanf("%f", "%f", &a, &b);
sum = a + b;
printf("Sum is %d\n", sum);
}
#include<stdio.h>
int main()
{
int a, b;
printf("Input any integer:\n");
scanf("%d",&a);
printf("Input any another integer:\n");
scanf("%d",&b);
printf("Before swap a=%d b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swap a=%d b=%d",a,b);
}
#include <stdio.h>

int main()
{
int sum,product,no,digit1,digit2,digit3;
printf("enter three digit number:\n");
scanf("%d", &no);

digit1=(no%10);
digit2=(no%100)/10;
digit3=(no/100);
sum=digit1+digit2+digit3;
product=digit1*digit2*digit3;

printf ("Sum is: %d\n",sum);


printf ("Product is: %d\n",product);
}
#include<stdio.h>

int main()
{
int a,b,c,d;
a=sizeof(int);
printf("Size of int is %d\n", a);
b=sizeof(float);
printf("Size of float is %d\n", b);
c=sizeof(double);
printf("Size of double is %d\n", c);
d=sizeof(char);
printf("Size of char is %d\n", d);
}
Assignment III
#include<stdio.h>

int main()
{
int a,x,y,z;
printf("Input a three integer number.\n");
scanf("%d", &a);
z=(a%10);
y=(a%100)/10;
x=(a/100);
printf("%d%d%d\n", x,y,z);
printf("%d%d\n", y,z);
printf("%d\n",z);
}
#include <stdio.h>
#include <math.h>

int main()
{
int a,x,y,z,b;
printf("Input a three digits integer number.\n");
scanf("%d", &a);
z=pow(a%10,3);
y=pow((a%100)/10,3);
x=pow(a/100,3);
b=x+y+z;
(a==b)?printf("The number %d is an Armstrong Number\n", a):printf("The number %d is
not an Armstrong Number\n", a);
}
#include <stdio.h>
#include <math.h>

int main()
{
int a,b,c;
printf("To check Automorphic number\n");
printf("Input a integer number.\n");
scanf("%d", &a);
b=(a*a)%10;
c=b%10;
a=a%10;
(a==c)?printf("The number %d is an Automorphic Number\n", a):printf("The number %d is
not an Automorphic Number\n", a);
}
#include <stdio.h>
#include <math.h>

int main()
{
int a;
float x,s,c;
printf("Enter any Angle:\n");
scanf("%d", &a);
x = a * 3.14f/180;
s = sin(x);
c = cos(x);
printf("sin(%d) is %f\n", a,s);
printf("cos(%d) is %f\n", a,c);
}
#include <stdio.h>

int main()
{
int a,b,c;
printf("Enter three Integer Number:\n");
scanf("%d%d%d", &a,&b,&c);
(a>b&&a>c)?printf("%d is the largest Number\n" ,a):(b>c)?printf("%d is the largest
Number\n", b):printf("%d is the largest Number\n", c);
(a<b&&a<c)?printf("%d is the Smallest Number\n" ,a):(b<c)?printf("%d is the Smallest
Number\n", b):printf("%d is the Smallest Number\n", c);
}
#include <stdio.h>

int main()
{
int a,x,y,z,b;
printf("Input a Three Digit Integer Number.\n");
scanf("%d", &a);
x=(a/100);
y=(a%100)/10;
z=(a%10);
b=x+(10*y)+(z*100);
printf("The Inverse Number Is %d\n", b);
}
#include <stdio.h>

int main()
{
float b;
int a,x,y,z;
printf("Enter a Number with three digits before the decimal places:\n");
scanf("%f",&b);
a=b;
z=(a%10);
y=((a%100)/10);
x=(a/100);
printf("%d\n",z);
printf("%d%d\n",y,z);
printf("%d%d%d\n",x,y,z);
}
Assignment IV
#include <stdio.h>

int main()
{
int a,b,c;
printf("Enter Three Integer Numbers:");
scanf("%d%d%d", &a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("%d is the Largest Number", a);
}
else
{
printf("%d is the Largest Number", c);
}
}
else
{
if(b>c)
{
printf("%d is the Largest Number", b);
}
else
{
printf("%d is the Largest Number", c);
}
}
}
#include <stdio.h>

int main()
{
char x;
printf("Enter any numbers or character:");
scanf("%c", &x);
if(x<='9'&&x>='0')
{
if(x%2==0&&x%5==0)
{
printf("%c - is a Number which is divisible by 2 and 5", x);
}
else
{
printf("%c - is a Number not divisible by 2 and 5", x);
}
}
else
{
if(x>='a'&&x<='z')
{
printf("%c - is a character in lowercase", x);
}
else if(x>='A'&&x<='Z')
{
printf("%c - is a character in uppercase", x);
}
}
printf("\n");
}
#include <stdio.h>

int main()
{
int customerid, unit;
float charges, surcharge, net;
char name[25];
printf("Enter your id, name and units consumed\n");
scanf("%d %s%d", &customerid, &name, &unit);
if(unit>=100&&unit<400)
{
if(unit<=199)
{
charges=1.2f*unit;
surcharge=0;
}
else
{
charges=1.5f*unit;
surcharge=0;
}
}
else if(unit>=400)
{
if(unit<600)
{
charges=1.8f*unit;
surcharge=0.15f*charges;
}
else
{
charges=2.0f*unit;
surcharge=0.15f*charges;
}
}
net = charges + surcharge;
printf("Customer Id - %d\nName - %s\nUnits consumed - %d\n", customerid, name, unit);
printf("Amount - %f\nSurcharge amount - %f\nNet Amount - %f\n", charges, surcharge,
net);
}
#include <stdio.h>

int main()
{
char a;
printf("Enter Grades(E,V,G,A,F):\n");
scanf("%c",&a);
switch(a)
{
case 'E' : printf("Excellent\n");
break;
case 'V' : printf("Very Good\n");
break;
case 'G' : printf("Good\n");
break;
case 'A' : printf("Average\n");
break;
case 'F' : printf("Fail\n");
break;
default: printf("You input wrong Grades.\n");;
}
}
#include <stdio.h>

int main()
{
int t;
printf("Enter temperature reading in centigrade:\n");
scanf("%d",&t);
if (t<0)
{
printf("Freezing Weather\n");
}
else if (t>0&&t<10)
{
printf("Very Cold Weather\n");
}
else if (t>10&&t<20)
{
printf("Cold Weather\n");
}
else if (t>20&&t<30)
{
printf("Normal Weather\n");
}
else if (t>30&&t<40)
{
printf("Hot Weather\n");
}
else if (t>40&&t<50)
{
printf("Very Hot Weather\n");
}
}
#include <stdio.h>

int main()
{
int c,m,p,t,tcm;
printf("Enter Your Physics, Chemistry and Mathematics Marks:\n");
scanf("%d%d%d",&p,&c,&m);
t = p+c+m;
tcm = c+m;
if (m>=65&&p>=55&&c>=60&&t>=190&&tcm>=130)
{
printf("You are eligible for admission.\n");
}
else
{
printf("You are not eligible for admission.\n");
}
}
#include <stdio.h>

int main()
{
int a,r=0,t;
printf("Enter a Number to check weather it is a palindrome or not:\n");
scanf("%d",&a);
t = a;

while (t != 0)
{
r = r * 10;
r = r + t%10;
t = t/10;
}

if (a == r)
printf("%d is a palindrome number.\n", a);
else
printf("%d isn't a palindrome number.\n", a);

}
#include <stdio.h>

int main()
{
float bs,hra,da,gs;
printf("Enter your Basic Salary:\n");
scanf("%f",&bs);
if (bs<=10000)
{
hra = 0.2f*bs;
da = 0.8f*bs;
}
else if (bs<=20000)
{
hra = 0.25f*bs;
da = 0.9f*bs;
}
else if (bs>20000)
{
hra = 0.30f*bs;
da = 0.95f*bs;
}
gs = bs + hra + da;
printf("Your Gross Salary is %f\n", gs);
}
Assignment V
#include <stdio.h>
int main()
{
int a, num=0;
printf("Enter any Number:\n");
scanf("%d",&a);
while(a != 0)
{
num = (num * 10) + (a % 10);
a /= 10;
}

while(num != 0)
{
switch(num % 10)
{
case 0: printf("Zero ");
break;
case 1: printf("One ");
break;
case 2: printf("Two ");
break;
case 3: printf("Three ");
break;
case 4: printf("Four ");
break;
case 5: printf("Five ");
break;
case 6: printf("Six ");
break;
case 7: printf("Seven ");
break;
case 8: printf("Eight ");
break;
case 9: printf("Nine ");
break;
}

num = num / 10;


}
}
#include <stdio.h>

int main()
{
int marks=0, grade;
printf("Enter marks out of 100:");
scanf("%d",&marks);
if (marks>=90&&marks<=100)
{
grade=1;
}
else if (marks>=60&&marks<90)
{
grade=2;
}
else if (marks>=50&&marks<60)
{
grade=3;
}
else if (marks>=30&&marks<50)
{
grade=4;
}
else if (marks>=0&&marks<30)
{
grade=5;
}
switch(grade)
{
case 1:printf("A grade\n");
break;
case 2:printf("B grade\n");
break;
case 3:printf("C grade\n");
break;
case 4:printf("D grade\n");
break;
case 5:printf("F grade\n");
break;
default:printf("You Entered Wrong marks.\n");
}
}
#include <stdio.h>

int main()
{
char month;
printf("Enter any character:");
scanf("%c",&month);
switch(month)
{
case 'j':printf("January, June and July\n");
break;
case 'a':printf("August and April\n");
break;
case 's':printf("September\n");
break;
case 'o':printf("October\n");
break;
case 'n':printf("November\n");
break;
case 'f':printf("February\n");
break;
case 'd':printf("December\n");
break;
case 'm':printf("March and May\n");
break;
case 'J':printf("January, June and July\n");
break;
case 'A':printf("August and April\n");
break;
case 'S':printf("September\n");
break;
case 'O':printf("October\n");
break;
case 'N':printf("November\n");
break;
case 'F':printf("February\n");
break;
case 'D':printf("December\n");
break;
case 'M':printf("March and May\n");
break;
default:printf("You Entered Wrong Input:\n");
}
}
#include <stdio.h>

int main()
{
int n, j, i, k, s;
printf("Enter No. of Rows:\n");
scanf("%d",&n);
for (i = 1; i <= n; i++)
{
for (s = 1; s <= (n-i); s++)
{
printf(" ");
}
for (j = i; j <= (2*i - 1); j++)
{
printf("%d", j);
}
for (k = (j-2); k >= i; k--)
{
printf("%d", k);
}
printf("\n");
}
}
#include <stdio.h>

int main()
{
int n,k=1;
printf("Enter Number of Rows:\n");
scanf("%d",&n);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
printf("%d ", k);
k++;
}
printf("\n");
}
}
#include <stdio.h>

int main()
{
int a ,r ,se=0 ,so=0;
printf("Enter Any 10 Numbers");
scanf("%d",&a);
for(a;a>0;a=a/10)
{
r=a%10;
if(r%2==0)
{
se = se + r;
}
else
{
so = so + r;
}
}
printf("Sum of Even Numbers : %d\n", se);
printf("Sum of Odd Numbers : %d\n", so);
}
Assignment VI
#include<stdio.h>

int main()
{
int i=1;
while(i<=5)
{
int j=1;
while(j<=5)
{
printf("%d\t",j);
j++;
}
printf("\n");
i++;
}
return 0;
}
#include<stdio.h>

int main()
{
for(int i=1;i<=500;i++){
int s=0;
for(int j=1;j<=i;j++){
if(i%j==0){
s=s+j;
}
}
if((s/2)==i){
printf("%d\n", i);
}
}
return 0;
}
#include <stdio.h>

int main()
{
int i, j, isPrime;
printf("All prime numbers between 1 to 500 are:\n",);
for(i=2; i<=500; i++)
{
isPrime = 1;
for(j=2; j<=i/2; j++)
{
if(i%j==0)
{
isPrime = 0;
break;
}
}
if(isPrime==1)
{
printf("%d, ", i);
}
}

return 0;
}
#include<stdio.h>

int main()
{
int x=0;
for(int i=1;i<=5;i++){
for(int j=1;j<=10;j++){
printf("%d\t", (i*j));
}
printf("\n");
}
return 0;
}
#include<stdio.h>

int add(int *a,int *b){


return (*a + *b);
}
int sub(int *a,int *b){
return (*a - *b);
}
int mul(int *a,int *b){
return (*a * *b);
}
int div(int *a,int *b){
return (*a / *b);
}

int main()
{
int x,y,n;
printf("Enter Two Number:\n");
scanf("%d%d", &x,&y);
printf("Enter Choice:\n1 - Addition\n2 - Subtraction\n3 - Multiply\n4 - Divide\n");
scanf("%d", &n);
switch(n){
case 1 : printf("Summation = %d\n", add(&x,&y));
break;
case 2 : printf("Difference = %d\n", sub(&x,&y));
break;
case 3 : printf("Multipication = %d\n", mul(&x,&y));
break;
case 4 : printf("Division = %d\n", div(&x,&y));
break;
}
return 0;
}

Assignment VII
#include<stdio.h>

void SeriesSum(int n)
{
int fact = 1, sum = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i ; j++)
{
fact = fact * j;
}
sum = sum + fact/i;
}
printf("sum = %d\n", sum);
}
int main()
{
int n;
printf("Enter n:\n");
scanf("%d", &n);
SeriesSum(n);
}
#include <stdio.h>

int counteven(int *n){


if(*n%2==0){
return 1;
}
else{
return 0;
}
}

int main()
{
int count = 0, n;
char choice;
printf("Want to Enter Numbers: \n");
printf("1. Yes - Y\n 2. No - N\n");
scanf("%c", &choice);
if(choice=='Y'){
scanf("%d", &n);
count = count + counteven(&n);
goto *16;
}
printf("No. of even Numbers : %d\n", count);
return 0;
}
#include <stdio.h>

int d_a(int *bs){


return *bs*0.2f;
}
int h_r_a(int *bs){
return *bs*0.1f;
}
void g_s(int *bs, int *da, int *hra){
printf("Gross Salary = %d\n", *bs + *da + *hra);
}

int main()
{
int bs, da, hra, gs;
printf("Enter Basic Pay:\n");
scanf("%d", &bs);
da = d_a(&bs);
hra = h_r_a(&bs);
g_s(&bs, &da, &hra);
return 0;
}
#include <stdio.h>

int Armstrong(int *n){


int x ,num;
int p = *n;
while(p != 0){
num = p % 10;
x = x + num*num*num;
p = p / 10;
}
(*n==x)?printf("%d is an Armstrong Number\n", *n):printf("%d is not an Armstrong
Number\n", *n);
return 0;
}
int isPrime(int *n){
int i, isPrime =1;
for(i=2; i<=*n/2; i++)
{
if(*n%i==0)
{
isPrime = 0;
break;
}
}
if(isPrime==1)
{
printf("%d is a Prime Number\n", *n);
}
else{
printf("%d is not a Prime Number\n", *n);
}
return 0;
}
int Prefect(int *n){
int s=0;
for(int i=1; i<=*n; i++){
if(*n%i==0){
s=s+i;
}
if((s/2)==*n){
printf("%d is a Perfect Number\n", *n);
}
else{
printf("%d is not a Prefect Number\n", *n);
}
}
return 0;
}
int main()
{
int n;
printf("Input any Number:\n");
scanf("%d", &n);
isPrime(&n);
Armstrong(&n);
Prefect(&n);
}
#include <stdio.h>

int factorial(int n){


int fact=1;
for (int i = 1; i <= n; i++){
fact = fact * i;
}
return fact;
}

void strong(int n){


int p, x, sum;
x = n;
while(n != 0){
p = n % 10;
sum = sum + factorial(p);
n = n / 10;
}
if (x == sum){
printf(" %d", n);
}
}
int main(){
int lowerlimit, upperlimit;
printf("Enter lower limit: ");
scanf("%d", &lowerlimit);
printf("Enter upper limit: ");
scanf("%d", &upperlimit);
printf("Strong Number between %d to %d are :", lowerlimit, upperlimit);
for (int i = lowerlimit; i <= upperlimit; i++){
strong(i);
}
return 0;
}
Assignment VIII
#include <stdio.h>

int input(int n, int arr[]){


for (int i = 0; i < n; i++){
scanf("%d", &arr[i]);
arr++;
}
return 0;
}

int display(int *n, int arr[]){


for (int i = 0; i < *n; i++){
printf("%d - %d", i, arr[i]);
arr++;
}
return 0;
}

int min_max(int n, int arr[]){


int min=100, max=0;
for (int i = 0; i < n; i++){
if (max<=arr[i]){
max = arr[i];
}
if (min>=arr[i]){
min = arr[i];
}
arr++;
}
printf("min : %d and max : %d\n", min, max);
return 0;
}

int count(int *n, int arr[]){


int sum;
for (int i = 0; i < *n; i++)
{
sum = sum + arr[i];
}
printf("Average : %d\n", sum/2);
}

int main(){
int n, student_array[10];
printf("Enter Number of student(less than 10) :");
scanf("%d", &n);
printf("Enter Marks of the students:\n");
input(n, student_array);
display(&n, student_array);
min_max(n, student_array);
count(&n, student_array);
}

You might also like