0% found this document useful (0 votes)
31 views

Program File

The document contains 12 code snippets with outputs that demonstrate various C programming concepts like input/output, arithmetic operations, conditional statements, and type conversions using printf() and scanf() functions. The codes include programs to print patterns, take user input, perform calculations, find areas of shapes, convert between temperature scales and time units. Each code is accompanied by its output and includes header information like aim, experiment number, date etc.

Uploaded by

muchhalabhavin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Program File

The document contains 12 code snippets with outputs that demonstrate various C programming concepts like input/output, arithmetic operations, conditional statements, and type conversions using printf() and scanf() functions. The codes include programs to print patterns, take user input, perform calculations, find areas of shapes, convert between temperature scales and time units. Each code is accompanied by its output and includes header information like aim, experiment number, date etc.

Uploaded by

muchhalabhavin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 80

Marwadi University

Faculty of Engineering and Technology


Department of Information and Communication Technology
Aim: W.A.P to print the following pattern on the screen using
printf() function

#
Subject: ICP
(01CT1101) ##

###

####
Experiment No: 1 Date: Enrolment No: 92301733043

Code:
#include <stdio.h>
int main()
{
printf("#\n##\n###\n####\n");
return 0;
}
Output:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P to print your name & address on to the screen using
(01CT1101) printf() function.
Experiment No: 2 Date: Enrolment No: 92301733043

Code:
#include <stdio.h>
int main()
{
printf("Bhavin Muchhala\n7,gayatri nagar,jalaram chowk");
return 0;
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P to print college name & address in center of the screen
(01CT1101) & surrounded by a border.
Experiment No: 3 Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
main()
{
printf(" \n\n\n\n\n\ \n");

printf(" -------------------\n");
printf(" university name:|marwadi university|\n");
printf(" -------------------\n");
printf(" -----------------------------------------\n");
printf(" address:|rajkot morbi
highway,mitana,rajkot:360003|\n");
printf(" -----------------------------------------\n");

Page Number:-
printf("\n\n\n\n\n\n\n\n\n \n");
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP AimW.A.P that will ask user to input a character, integer and a float
(01CT1101) value and display the same back to the screen.
Experiment No: 4 Date: Enrolment No: 92301733043

Code:
#include <stdio.h>
int main()
{
int Integer;
char Character;
float InputFloat;

printf(" Please Enter a Character : ");


scanf("%c", &Character);

printf(" Please Enter an Integer Value : ");


scanf("%d", &Integer);

printf(" Please Enter Float Value : ");


scanf("%f", &InputFloat);

printf(" \n The Integer Value is : %d", Integer);


printf(" \n The Character is : %c", Character);
printf(" \n The Float Value is : %f", InputFloat);

Page Number:-
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P that asks user to input three nos. and displays the
(01CT1101) average of it.
Experiment No: 5 Date: Enrolment No: 92301733043

Code:
#include <stdio.h>

int main() {
int avg,x,y,z;
printf("enter value of x,y,z");
scanf("%d%d%d",&x,&y,&z);
avg=(x+y+z)/3;
printf("%d",avg);

return 0;
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P that asks user to input two nos. and display addition,
(01CT1101) subtraction, multiplication and division of it
Experiment No: 6 Date: Enrolment No: 92301733043

Code:
#include <stdio.h>
int main() {
int sum,sub,multi,divi,x,y;
printf("enter value of x,y");
scanf("%d%d",&x,&y);
sum=x+y;
sub=x-y;
multi=x*y;
divi=x/y;
printf("your sum is:%d\n",sum);
printf("your sub is:%d\n",sub);
printf(" your multi is :%d\n",multi);
printf("your divi is:%d",divi); }
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P to demonstrate the use of arithmetic operations (+, - ,
(01CT1101) /, *) inside the printf() function for two operands entered by the user
Experiment No: 7 Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int a,b;
printf("enter the first value:\n");
scanf("%d",&a);
printf("enter second value:");
scanf("%d",&b);
printf("addition:%d+%d=%d\n",a,b,a+b);
printf("substraction:%d-%d=%d\n",a,b,a-b);
printf("multiplication:%d*%d=%d\n",a,b,a*b);
if(b!=0)
{
printf("division:%d/%d=%d\n",a,b,a/b);
}
else
{
printf("division is not possible.");
}

Page Number:-
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P that asks user to input two nos. and swaps the value of
(01CT1101) it. 1) using 3 variables 2) using 2 variables
Experiment No: 8 Date: Enrolment No: 92301733043

using 3 variables :
Code:
#include<stdio.h>
int main()
{
int a,b,c;
printf("enter value of a,b");
scanf("%d%d",&a,&b);
c=a;
a=b;

Page Number:-
b=c;
printf("%d%d",a,b);
}
OUTPUT:

using 2 variables :
Code:
#include<stdio.h>
int main()
{
int a,b;
printf("enter value of a,b");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("%d%d",a,b);
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P that asks user to input a character and prints its ASCII
(01CT1101) value.
Experiment No: 9 Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
char c;
printf("enter the character:");
scanf("%c",&c);
printf("ASCII value of %c=%d",c,c);
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P that asks user to input temperature in Fahrenheit and
(01CT1101) convert it into Celsius by using the following formula.
Experiment No: 10 Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
int main()
{
int c,f;
printf("enter temperature in Fahrenheit");
scanf("%d",&f);
c=(f-32)/1.8;
printf("%d",c);
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P to find the area of circle, triangle, rectangle and
(01CT1101) square.
Experiment No: 11 Date: Enrolment No: 92301733043

Code:

For circle:
#include<stdio.h>
int main()
{
int r,x;
printf("enter value of r");
scanf("%d",&r);
x=3.14*r*r;
printf("%d",x);
}
OUTPUT:

Page Number:-
FOR triangle:
#include<stdio.h>
int main()
{
int b,h,x;
printf("enter value of b,h");
scanf("%d%d",&b,&h);
x=0.5*(b*h);
printf("%d",x);
}
OUTPUT:

Page Number:-
For Rectangle:
#include<stdio.h>
int main()
{
int b,h,x;
printf("enter value of b,h");
scanf("%d%d",&b,&h);
x=(b*h);
printf("%d",x);
}
OUTPUT:

Page Number:-
FOR Square:
#include<stdio.h>
int main()
{
int b,x;
printf("enter value of b");
scanf("%d",&b);
x=b*b;
printf("%d",x);
}

OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P that asks user to input data in years and displays the
(01CT1101) output in months and days.
Experiment No: 12 Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
int main()
{
int year,month,day;
printf("enter value of year");
scanf("%d",&year);
month=year*12;
day=year*365;
printf("%d\n",month);
printf("%d",day);
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P that asks user to input his age in years and display his
(01CT1101) age in months and days.
Experiment No: 13 Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
int main()
{
int age,month,day;
printf("enter value of age");
scanf("%d",&age);
printf("%d\n",month=age*12);
printf("%d",day=age*365);
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology
Aim: W.A.P that find out net salary of an employee. get the basic
Subject: ICP salary from him Applicable : TA => 5%, DA => 64%, HRA =>
(01CT1101) 12% on basic salary Applicable : Tax => 3%, PF => 12% on gross
salary GROSS SALARY = BASIC SALARY + TA + DA + HRA
NET SALARY = GROSS SALARY – TAX – PF
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include <stdio.h>

int main ()
{
float basic_salary;
float DA,TA;
float HRA,TAX;
float PF;
float gross_salary;
float net_salary;
printf("Input Basic Salary: ");
scanf("%f", &basic_salary);
DA = basic_salary * 64.0 / 100.0;
HRA = basic_salary * 12.0 / 100.0;
gross_salary = basic_salary + DA +TA + HRA;
PF = gross_salary * 12.0 / 100.0;
net_salary = gross_salary - TAX - PF;

Page Number:-
printf("Basic Salary: %.2f\n", basic_salary);
printf("DA: %.2f\n", DA);
printf("HRA: %.2f\n", HRA);
printf("Gross Salary: %.2f\n", gross_salary);
printf("PF: %.2f\n", PF);
printf("Net Salary: %.2f", net_salary);

}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P that asks user to enter principal amount, number of
(01CT1101) years and rate of interest and find the simple interest and compound
interest.
Experiment No: Date: Enrolment No: 92301733043

CODE:

Page Number:-
#include<stdio.h>
#include<math.h>
int main()
{
float p,t,r,si,ci;
printf("enter principal amount:\n");
scanf("%f",&p);
printf("enter time in year:\n");
scanf("%f",&t);
printf("enter rate in interest:\n");
scanf("%f",&r);
si=(p*t*r)/100.0;
ci=p*(pow(1+r/100,t)-1);

printf("simple interest = %0.3f \n",si);


printf("compound interest = %0.3f ",ci);
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P to compute distance between two points (x1, y1) &
(01CT1101) (x2, y2) using the following formula. D2 = (x2-x1)2 + (y2-y1)2
Experiment No: Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
int main()
{
int D,x1,x2,y1,y2;
printf("enter value of x1:");
scanf("%d",&x1);

Page Number:-
printf("entyer the value of x2:");
scanf("%d",&x2);
printf("enter the value of y1:");
scanf("%d",&y1);
printf("enter the value of y2:");
scanf("%d",&y2);
D=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
D*D;
printf("Answer is = %d",D*D);
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P that accepts a year & shows whether it is a leap year or
(01CT1101) not?

Page Number:-
Experiment No: Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
int main()
{
int year;
printf("enter the year:");
scanf("%d",&year);
if(year%4==0)
{
printf("Leap year");
}
else
{
printf("Not leapyear");
}
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP
(01CT1101) Aim: W.A.P to find that number is positive or not.

Experiment No: Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
int main()
{
int x;
printf("enter value of x:");
scanf("%d",&x);
if(x>0)
{
printf("NO. is Positive");
}
else
{
printf("NO. is Negative");
}
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP
(01CT1101) Aim: W.A.P to check whether the entered no is odd or even

Experiment No: Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
int main()
{
int n;
printf("enter the value of n:");
scanf("%d",&n);
if(n%2==0)
{
printf("NO. is Even");

Page Number:-
}
else
{
printf("NO. is Odd");
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P to input 3 numbers and print the maximum out of
(01CT1101) them.
Experiment No: Date: Enrolment No: 92301733043

Code:
#include<stdio.h>

Page Number:-
int main()
{
int a,b,c;
printf("enter the \na:,b:,c:\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("a is Max.");
}
else
{
printf("c is Max.");
}
}
else
{
if(b>c)
{
printf("b is Max.");
}
else
{

Page Number:-
printf("c is Max.");
}
}

}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Aim: W.A.P that accepts student’s marks & calculate total


Subject: ICP percentage. Give the grade according to following criteria. Grade
(01CT1101) A+: - per above 80 Grade A- : - per between 70 & 80 Grade B+: -
per between 60 & 70 Grade B- : - per between 50 & 60 Grade C : -
per between 40 & 60 Grade F : - per. Below 40
Experiment No: Date: Enrolment No: 92301733043

Code:
#include<stdio.h>

Page Number:-
int main()
{
int a,b,c,d,per;
printf("enter the a:,b:,c:,d:");
scanf("%d%d%d%d",&a,&b,&c,&d);
per=(a+b+c+d)/4;
if(per>=80)
{
printf("Grade A+");
}
else if(per>=70)
{
printf("Grade A-");
}
else if(per>=60)
{
printf("Grade B+");
}
else if(per>=50)
{
printf("Grade B-");
}
else if(per>=40)
{

Page Number:-
printf("Grade C");
}
else
{
printf("Grade F");
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: W.A.P that accepts 3 nos. and display maximum, minimum &
(01CT1101) middle no entered by the user.
Experiment No: Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
int main()
{
int a,b,c;

Page Number:-
printf("enter value a: \n");
scanf("%d",&a);
printf("enter value b: \n");
scanf("%d",&b);
printf("enter value c: \n");
scanf("%d",&c);
if(a>b && a>c)
{
printf("max number = %d ",a);
}
else if(b>a && b>c)
{
printf("max number = %d ",b);
}
else if(c>a && b<c)
{
printf("max number = %d ",c);
}
if(a>b&&a<c || a>c&&a<b)
{
printf("med number = %d ",a);
}
else if(b>a&&b<c || b>c&&b<a)
{

Page Number:-
printf("med number = %d ",b);
}
else if(c>a&&b<c || c>b&&c<a)
{
printf("med number = %d ",c);
}
if(a<b&&a<c)
{
printf("min number = %d ",a);
}
else if(b<a&&b<c)
{
printf("min number = %d ",b);
}
else if(c<a&&b<c)
{
printf("min number = %d ",c);
}
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 23) W.A.P that accepts a character from user & checks
(01CT1101) whether given character is uppercase, lower case, digit or special
character. 1) Using ASCII values 2) Using built-in functions
Experiment No: Date: Enrolment No: 92301733043

Code:

Output:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 24) W.A.P to get a character from user and print whether it is
(01CT1101) a VOWEL or a CONSONANT.
Experiment No: Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
int main()
{

Page Number:-
char x;
printf("enter any character:\n");
scanf("%c",&x);
if(x=='a'||x=='e'||x=='i'||x=='o'||x=='u')
{
printf("character is vowel.");
}
else if(x=='A'||x=='E'||x=='I'||x=='O'||x=='U')
{
printf("character is vowel.");
}
else
{
printf("character is consonant.");
}
}
Output:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 25) W.A.P to find vowels &consonants from a user input until
(01CT1101) ‘$’ is pressed using goto statement.
Experiment No: Date: Enrolment No: 92301733043

Code:

#include <stdio.h>

int main() {
char input;
int vowels = 0, consonants = 0;

printf("Enter a character: ");


while (1) {
scanf("%c", &input);
if (input == '$') {
break;
}
if ((input >= 'a' && input <= 'z') || (input >= 'A' && input <= 'Z')) {
switch (input) {
case 'a':
case 'e':
case 'i':
case 'o':

Page Number:-
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
vowels++;
break;
default:
consonants++;
break;
}
}
}

printf("Number of vowels: %d\n", vowels);


printf("Number of consonants: %d\n", consonants);

return 0;
}

Output:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 26) W.A.P that calculates the sum of given numbers until user
(01CT1101) says “NO” using goto statement.
Experiment No: Date: Enrolment No: 92301733043

Code:

Output:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 27) W.A.P to demonstrate simple calculator using 1) Switch
(01CT1101) case statement.
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int a,b;
char operation;
printf("enter the operation (+,-,*,/)\n");
scanf("%c",&operation);
printf("enter the a: & b:");
scanf("%d%d",&a,&b);
switch (operation)
{
case '+': printf("%d+%d=%d",a,b,a+b);
break;
case '-': printf("%d-%d=%d",a,b,a-b);
break;
case '*': printf("%d*%d=%d",a,b,a*b);
break;

Page Number:-
case '/': printf("%d/%d=%d",a,b,a/b);
break;
default:
{
printf("enter valid operation");
}
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP
(01CT1101) Aim: 28) solve example 4 using switch case

Experiment No: Date: Enrolment No: 92301733043

Page Number:-
Code:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 29) W.A.P to print day name according to given number
(01CT1101) using switch case statement
Experiment No: Date: Enrolment No: 92301733043

Code:
#include<stdio.h>
int main()
{
int day;
printf("enter day no. (0 to 6)\n");
scanf("%d",&day);
switch(day)
{
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");

Page Number:-
break;
case 6: printf("SATURDAY");
break;
defualt:
printf("enter valid day no.");
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 30) W.A.P to print month name according to given number
(01CT1101) using if..else ladder.
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{

Page Number:-
int month;
printf("enter month no. (0 to 11)\n");
scanf("%d",&month);
if(month==0)
{
printf("JANUARY");
}
else if(month==1)
{
printf("FEBRUARY");
}
else if(month==2)
{
printf("MARCH");
}
else if(month==3)
{
printf("APRIL");
}
else if(month==4)
{
printf("MAY");
}
else if(month==5)

Page Number:-
{
printf("JUNE");
}
else if(month==6)
{
printf("JULY");
}
else if(month==7)
{
printf("AUGUST");
}
else if(month==8)
{
printf("SEPTEMBER");
}
else if(month==9)
{
printf("OCTOBER");
}
else if(month==10)
{
printf("NOVEMBER");
}
else if(month==11)

Page Number:-
{
printf("DECEMBER");
}
else
{
printf("enetr valid month no.");
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 30) W.A.P to print month name according to given number
(01CT1101) using switch case statement.
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()

Page Number:-
{
int month;
printf("enter month no. (0 to 11)\n");
scanf("%d",&month);
switch (month)
{
case 0: printf("JUNUARY");
break;
case 1: printf("FEBRUARY");
break;
case 2: printf("MARCH");
break;
case 3: printf("APRIL");
break;
case 4: printf("MAY");
break;
case 5: printf("JUNE");
break;
case 6: printf("JULY");
break;
case 7: printf("AUGUST");
break;
case 8: printf("SEPTEMBER");
break;

Page Number:-
case 9: printf("OCTOMBER");
break;
case 10: printf("NOVEMBER");
break;
case 11: printf("DECEMBER");
break;

default:
{
printf("enter valid month no.");
}
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 31) W.A.P to generate simple calculator using switch case
(01CT1101) statement.

Page Number:-
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int a,b;
char operation;
printf("enter the operation (+,-,*,/)\n");
scanf("%c",&operation);
printf("enter the a: & b:");
scanf("%d%d",&a,&b);
switch (operation)
{
case '+': printf("%d+%d=%d",a,b,a+b);
break;
case '-': printf("%d-%d=%d",a,b,a-b);
break;
case '*': printf("%d*%d=%d",a,b,a*b);
break;
case '/': printf("%d/%d=%d",a,b,a/b);
break;
default:
{

Page Number:-
printf("enter valid operation");
}
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP
(01CT1101) Aim: 32) W.A.P to print the sum of first 100 natural numbers.

Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int sum=0,i=0;
while(i<=100)
{
sum=sum+i;

Page Number:-
i++;
}
printf("%d",sum);
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP
(01CT1101) Aim: 33) W.A.P to print 1 to 10 numbers.

Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int i=1;
while(i<=10)
{
printf("%d\n",i);

Page Number:-
i++;
}
}
OUTPUT;

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP
(01CT1101) Aim: 34) W.A.P to print the sum of the series 1+ 2 + 3 + ……. + n

Experiment No: Date: Enrolment No: 92301733043

CODE:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 35) W.A.P to print the sum of the series 1+ 3 + 5 + 7 +…….
(01CT1101) +n-1
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int n,i,sum=0;
printf("enter n:");
scanf("%d",&n);
i=1;
for(i;i<=n-1;i=i+2)
sum=sum+i;
printf("%d",sum);
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 36) W.A.P to print the sum of the series 1^2 + 2^2 + 3^2 +
(01CT1101) ……. + n^2
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int n;
printf("enter n:");
scanf("%d",&n);
int sum=0;
int i=1;
for(i;i<=n;i++)sum +=i*i;
printf("%d",sum);
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 37) W.A.P to print the sum of the series X + X^2 + X^3 +
(01CT1101) X^4 + ……. + X^n
Experiment No: Date: Enrolment No: 92301733043

CODE:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 38) W.A.P to find factorial of given no. n! = 1 * 2 * 3 * ….. *
(01CT1101) (n - 1) * n
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int x,fact=1,n;
printf("enter a no. to find fectorial:");
scanf("%d",&n);
x=1;
while(x<=n)
{
fact=fact*x;
x++;

Page Number:-
}
printf("Factorial of %d is:%d",n,fact);
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 39) W.A.P to find the sum of the series 1! + 2! + 3! + ……. +
(01CT1101) n!
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int x,fact=1,n,sum=0;
printf("enter a no. to find fectorial:");
scanf("%d",&n);
x=1;
while(x<=n)

Page Number:-
{
fact=fact*x;
sum+=fact;
x++;
}
printf("Factorial of %d is:%d",n,sum);
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 40) W.A.P to find the sum of the series X/1! – X^3 /3! + X^5
(01CT1101) /5! – X^7 /7! upto n terms.
Experiment No: Date: Enrolment No: 92301733043

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 41) W.A.P to print Fibonacci series upto n terms. Enter value
(01CT1101) for n = 7 Fibonacci Series = 1 1 2 3 5 8 13
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int n,i,a=0,b=1,c;
printf("enter n:");
scanf("%d",&n);
printf("Fibonacci series up to %d terms:\n",n);
for(i=0;i<n;i++)
{
if(i<=1)
c=i;
else
{
c=a+b;
a=b;
b=c;
}
printf("%d ",c);

Page Number:-
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 42) W.A.P to print the reverse of the no. entered by the user.
(01CT1101) Enter no. = 12345 Reverse no. = 54321
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int i,n;
printf("enetr n:");
scanf("%d",&n);
while(n!=0)
{

Page Number:-
i=n%10;
printf("%d",i);
n=n/10;
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 43) W.A.P to print the sum of the digits of the no. entered by
(01CT1101) the user. Enter no. = 12345 Sum = 15
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int n,a,sum=0,remainder;
printf("enter an integer\n");
scanf("%d",&n);

Page Number:-
a=n;
while(a!=0)
{
remainder=a%10;
sum+=remainder;
a=a/10;
}
printf("sum of digits of %d\n",sum);
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 44) W.A.P to check whether entered no. is Armstrong or not.
(01CT1101) Armstrong number: - 153 = 1^3 + 5^3 + 3^3
Experiment No: Date: Enrolment No: 92301733043

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP
(01CT1101) Aim: 45) W.A.P to print all the Armstrong nos between 0 and 999

Experiment No: Date: Enrolment No: 92301733043

CODE:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 46) W.A.P to generate all the factors of a number entered by
(01CT1101) the user. Enter no. = 12 Factors are = 1, 2, 3, 4, 6, 12
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int n,i;
printf("enter n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
printf("%d,",i);
}

Page Number:-
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 47) W.A.P to check whether entered no. is Perfect or not.
(01CT1101) Perfect number: - 6 * 2 = 1* 2 * 3 * 6
Experiment No: Date: Enrolment No: 92301733043

CODE:
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP
(01CT1101) Aim: 48) W.A.P to print all the Perfect nos between 0 and 999.

Experiment No: Date: Enrolment No: 92301733043

CODE:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP
(01CT1101) Aim: 49) W.A.P to check whether entered number is prime or not.

Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int i,n,flag=0;
printf("enter the number:\n");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("%d is a prime number",n);
}

Page Number:-
else
{
printf("%d is not a prime number",n);
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 50) W.A.P to find all the prime nos. between lower limit and
(01CT1101) upper limit. Lower limit = 3 Upper limit = 20 Prime Series = 5, 7,
11, 13, 17, 19
Experiment No: Date: Enrolment No: 92301733043

CODE: #include <stdio.h>

int main() {
int low, high, i, flag;
printf("Enter two numbers(intervals): ");
scanf("%d %d", &low, &high);

Page Number:-
printf("Prime numbers between %d and %d are: ", low, high);
while (low < high) {
flag = 0;
if (low <= 1) {
++low;
continue;
}
for (i = 2; i <= low / 2; ++i) {

if (low % i == 0) {
flag = 1;
break;
}
}

if (flag == 0)
printf("%d ", low);
++low;
}
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 51) W.A.P. to find the GCF and LCM of two nos. entered by
(01CT1101) the user. Enter no1. = 24 Enter no2. = 36 GCF = 12 LCM = 72
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include <stdio.h>
int main() {
int a, b, x, y, t, gcd, lcm;

printf("Enter two integers\n");


scanf("%d%d", &x, &y);

a = x;
b = y;

while (b != 0) {
t = b;

Page Number:-
b = a % b;
a = t;
}

gcd = a;
lcm = (x*y)/gcd;

printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);


printf("Least common multiple of %d and %d = %d\n", x, y, lcm);
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Subject: ICP Aim: 52) W.A.P. to print the binary and octal equivalent of the
(01CT1101) decimal no. entered by the user.
Experiment No: Date: Enrolment No: 92301733043

Page Number:-
CODE:
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Aim: 53) W.A.P. to print the following pattern using for loop.

Subject: ICP **
(01CT1101)
***

****

*****
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}

Page Number:-
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology
Aim: 54) W.A.P. to print the following pattern using for loop.
*****

*****
Subject: ICP
(01CT1101) *****

*****

*****
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{

Page Number:-
for(j=1;j<=5;j++)
{
printf("*");
}
printf("\n");
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology
Aim: 55) W.A.P to print the following pattern using for loop.

Subject: ICP 12
(01CT1101)
123

1234

12345
Experiment No: Date: Enrolment No: 92301733043

Page Number:-
CODE:
#include<stdio.h>
int main()
{
int i,j,n = 5;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology

Page Number:-
Aim: 56) W.A.P to print the following pattern using for loop.

Subject: ICP 23
(01CT1101)
456

7 8 9 10

11 12 13 14 15
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include <stdio.h>
int main()
{
int i,j,c=1, n;
printf("enter number of terms\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",c);
c++;
}
printf("\n");
}
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology
Aim: 57) W.A.P. to print the following pattern using for loop for n
rows where n is entered by the user.

1
Subject: ICP 21
(01CT1101)
321

4321

54321
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include<stdio.h>
int main()
{
int i,j,n;
printf("enetr n:");
scanf("%d",&n);
for(i=1;i<=n;i++)

Page Number:-
{
for(j=i;j>=1;j--)
{
printf("%d",j);
}
printf("\n");
}
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
`
Department of Information and Communication Technology
Aim: 58) W.A.P. to print the following pattern using for loop for n
rows where n is entered by the user.

Subject: ICP 5
(01CT1101)
54

543

Page Number:-
5432

54321
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include <stdio.h>
int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
{
printf("%d",j);
}
printf("\n");
}
}
OUTPUT:

Page Number:-
Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology
Aim: 58) W.A.P. to print the following pattern using for loop for n
rows where n is entered by the user.

a
Subject: ICP bc
(01CT1101)
def

ghij

klmno
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include <stdio.h>

int main() {
int i, j, k = 0, n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; ++j) {
printf("%c ", 'a' + k++);
}
printf("\n");
}

Page Number:-
return 0;
}
OUTPUT:

Marwadi University
Faculty of Engineering and Technology
Department of Information and Communication Technology
Aim: 59) W.A.P. to print the following pattern using for loop for n
rows where n is entered by the user.

1
Subject: ICP
(01CT1101) 123

12345

1234567
Experiment No: Date: Enrolment No: 92301733043

CODE:
#include <stdio.h>
int main() {
int n;
printf("Enter the number of rows (n): ");
scanf("%d", &n);

Page Number:-
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
printf(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
printf("%2d ", k);
}
printf("\n");
}
}
OUTPUT:

Page Number:-

You might also like