DO NOT MISS

Ads

Tuesday 19 July 2016

C-Programs Using String




* Write a program to print student details and find out the total marks and average.



#include<stdio.h>
#include<conio.h>

void main()

      {

             
int sno,c,cpp,java,total;
             float avg;
             char sname[20];
             clrscr();

             printf("enter a student number:");
             scanf("%d",&sno);

             printf("enter a student name:");
             scanf("%s",&sname);

             printf("enter a c & cpp & java marks:");
             scanf("%d%d%d",&c,&cpp,&java);

             total=c+cpp+java;
             avg=total/3;

             printf("the total marks is=%d\n",total);
             printf("the average marks is=%2.2f\n",avg);

             getch();

     }


Output:-

Enter a student number:1214 
Enter a student name:Prasad
Enter a c & cpp & java marks: 45 67 89 
The total marks is=201 
The average marks is=67.00

* Write a program to print employee details and find out the net salary.

#include<stdio.h> 

#include<conio.h> 



void main() 



        { 

              int empno,sal,twd,tpd; 
              char empname[20]; 
              float netsal; 
              clrscr(); 

              printf("enter a empno:"); 
              scanf("%d",&empno); 

              printf("enter a empname:"); 
              scanf("%s",&empname); 

              printf("enter a salary:"); 
              scanf("%d",&sal); 

              printf("enter a total working days:"); 
              scanf("%d",&twd); 

              printf("enter a total present days:"); 
              scanf("%d",&tpd); 

              netsal=(sal/twd)*tpd; 
              printf("the net salary is:=%2.2f\n",netsal); 

              getch(); 

       }
Output:-

enter a empno:4587 
enter a empname:sanker 
enter a salary:12000
enter a total working days:30 
enter a total present days:24 
the net salary is=9600.00


* Write a program to print loan details and find out the monthly installments.



#include<stdio.h>
#include<conio.h>

void main()

       {

             
int loan,nomonths;
             float moninstal,interest=0.02;
             clrscr();

             printf("enter loan:");
             scanf("%d",&loan);

             printf("enter nomonths:");
             scanf("%d",&nomonths);

            moninstal=(loan*interest*nomonths+loan)/nomonths;
            printf("the interest is:=%2.2f\n",interest);
            printf(" monthly installment is:=%2.2f\n",moninstal);

            getch();

     }

Output:-


enter a loan:15000
enter a no of months:24
the interest is:0.02
monthly installment is:925.00

* write a program to print your Address.


#include<stdio.h>
#include<conio.h>

void main()

       {

               
char name[20],fname[20],strt[20],town[20],mandal[20],
dt[20],state[20];
                int dno;
                long int pincode;
                clrscr();

                printf("enter your name is:");
                scanf("%s",&name);

                printf("enter your fname is:");
                scanf("%s",&fname);

                printf("enter your dno:");
                scanf("%d",&dno);

                printf("enter your strt:");
                scanf("%s",strt);

                printf("enter your town:");
                scanf("%s",town);

                printf("enter your mandal:");
                scanf("%s",mandal);

                printf("enter your dt:");
                scanf("%s",&dt);

                printf("enter your state:");
                scanf("%s",&state);

                printf("enter your pincode:");
                scanf("%ld",&pincode);

                clrscr();

                printf("address:\n");
                printf("%s",name);
                printf("%s",fname);
                printf("%d",dno);
                printf("%s",strt);
                printf("%s",town);
                printf("%s",mandal);
                printf("%s",dt);
                printf("%ld",pincode);

                getch();

}
Output:-

enter your name is:prasad
enter your fname is:sanker
enter your dno is:516
enter your strt:tnagar
enter your town:tenali
enter your mandal:tenali
enter your dt:guntur
enter your pincode:522201
address:
prasad
sanker
516
tnagar
tenali
tenali
guntur
522201
_____________________________________________
>> Back to C-Language Notes (Topic Wise)
-----------------------------------------------------------------------------------------------

Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims